我有一个在 youtube 上学会制作的抽屉
https://www.youtube.com/watch?v=JLICaBEiJS0&list=PLQkwcJG4YTCSpJ2NLhDTHhi6XBNfk9WiC&index=31 菲利普·拉克纳
我想将抽屉添加到我的应用程序中,该应用程序有多个屏幕,其中一些不需要抽屉,因此我使用屏幕实现了导航,并且一些屏幕还需要将抽屉包裹在其顶部。
这是抽屉的代码
val scaffoldState = rememberScaffoldState()
val scope = rememberCoroutineScope()
Scaffold(
drawerGesturesEnabled = scaffoldState.drawerState.isOpen,
scaffoldState = scaffoldState, topBar = {
AppBar(onNavigationIconClick = {
scope.launch {
scaffoldState.drawerState.open()
}
})
}, drawerContent = {
DrawerHeader()
DrawerBody(items = listOf(
MenuItem(
id = "home",
title = "Home",
contentDescription = "Go to home screen",
icon = Icons.Default.Home
),
MenuItem(
id = "settings",
title = "Settings",
contentDescription = "Go to Settings screen",
icon = Icons.Default.Settings
),
MenuItem(
id = "help",
title …
Run Code Online (Sandbox Code Playgroud) lambda android function-parameter kotlin android-jetpack-compose
我正在用 c 编写一个名为:“shell”(我模仿 shell)的程序,我想编写一些测试以确保我遵循所有测试用例,所以我尝试使用#include <assert.h>
但我不明白如何模仿终端中的用户输入。我尝试使用包含文本的文件并更改stdin
为该输入文件并重定向stdout
到输出文件,但它不起作用。
我还尝试使用该函数将输入插入到终端system()
,但效果不佳。
shell 程序如何运行的示例
所以shell.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main()
{
char buf[1024];
while (1)
{
fgets(buf, 1024, stdin);
if (strncmp(buf, "quit", 4) == 0)
{
exit(0);
}
int fildes[2];
pipe(fildes);
if (fork() == 0)
{
close(fildes[0]);
dup2(fildes[1], STDOUT_FILENO);
execlp("ls", "ls", "-l", NULL);
perror("exec error");
exit(1);
}
else
{
close(fildes[1]);
read(fildes[0], buf, 1024);
printf("%s", buf);
}
}
return 0; …
Run Code Online (Sandbox Code Playgroud)