Implement TERMINAL_DIMENSIONS op for the terminal device, CE add terminfo command
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m59s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m59s
This commit is contained in:
@@ -5,7 +5,7 @@ $(eval $(call add_lib,libprocess))
|
|||||||
$(eval $(call add_lib,libaux))
|
$(eval $(call add_lib,libaux))
|
||||||
$(eval $(call add_lib,libarena))
|
$(eval $(call add_lib,libarena))
|
||||||
$(eval $(call add_lib,libioutil))
|
$(eval $(call add_lib,libioutil))
|
||||||
$(eval $(call add_include,libterminal))
|
$(eval $(call add_lib,libterminal))
|
||||||
$(eval $(call add_include,libkb))
|
$(eval $(call add_include,libkb))
|
||||||
|
|
||||||
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
||||||
|
|||||||
10
ce/interp.c
10
ce/interp.c
@@ -15,6 +15,7 @@
|
|||||||
#include <str_status.h>
|
#include <str_status.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
|
#include <terminal.h>
|
||||||
|
|
||||||
static bool run = true;
|
static bool run = true;
|
||||||
|
|
||||||
@@ -51,6 +52,12 @@ static void mkfile (struct context* context, char** file_paths, size_t files_cou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void terminfo (struct context* context) {
|
||||||
|
size_t cols = 0, rows = 0;
|
||||||
|
terminal_dimensions (&cols, &rows);
|
||||||
|
cprintf (context, "%zu x %zu\n", cols, rows);
|
||||||
|
}
|
||||||
|
|
||||||
static void mkdir (struct context* context, char** dir_paths, size_t dirs_count) {
|
static void mkdir (struct context* context, char** dir_paths, size_t dirs_count) {
|
||||||
char volume[VOLUME_MAX];
|
char volume[VOLUME_MAX];
|
||||||
const char* path;
|
const char* path;
|
||||||
@@ -248,6 +255,7 @@ static void help (struct context* context) {
|
|||||||
cprintf (context, "mkdir <directory path>\n");
|
cprintf (context, "mkdir <directory path>\n");
|
||||||
cprintf (context, "rm <path>\n");
|
cprintf (context, "rm <path>\n");
|
||||||
cprintf (context, "edit <path>\n");
|
cprintf (context, "edit <path>\n");
|
||||||
|
cprintf (context, "terminfo\n");
|
||||||
cprintf (context, "quit\n");
|
cprintf (context, "quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +294,8 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
|||||||
rm (context, cmd->args, cmd->arg_count);
|
rm (context, cmd->args, cmd->arg_count);
|
||||||
} else if (strcmp (cmd->name, "edit") == 0) {
|
} else if (strcmp (cmd->name, "edit") == 0) {
|
||||||
edit (context, cmd->args[0]);
|
edit (context, cmd->args[0]);
|
||||||
|
} else if (strcmp (cmd->name, "terminfo") == 0) {
|
||||||
|
terminfo (context);
|
||||||
} else {
|
} else {
|
||||||
char volume[VOLUME_MAX];
|
char volume[VOLUME_MAX];
|
||||||
const char* path;
|
const char* path;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
/* terminal device */
|
/* terminal device */
|
||||||
#define TERMINAL_PUTSTR 0
|
#define TERMINAL_PUTSTR 0
|
||||||
|
#define TERMINAL_DIMENSIONS 1
|
||||||
|
|
||||||
/* keyboard device */
|
/* keyboard device */
|
||||||
#define KB_READ_KEY 0
|
#define KB_READ_KEY 0
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ struct device* device_create (const char* key, device_op_func_t* ops, size_t ops
|
|||||||
void terminal_device_init (void) {
|
void terminal_device_init (void) {
|
||||||
device_op_func_t ops[] = {
|
device_op_func_t ops[] = {
|
||||||
[TERMINAL_PUTSTR] = &terminal_putstr,
|
[TERMINAL_PUTSTR] = &terminal_putstr,
|
||||||
|
[TERMINAL_DIMENSIONS] = &terminal_dimensions,
|
||||||
};
|
};
|
||||||
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
|
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void terminal_fini (struct device* device) { (void)device; }
|
|||||||
|
|
||||||
int terminal_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
int terminal_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||||
void* a1, void* a2, void* a3, void* a4) {
|
void* a1, void* a2, void* a3, void* a4) {
|
||||||
(void)a2, (void)a3, (void)a4, (void)device;
|
(void)a2, (void)a3, (void)a4, (void)device, (void)rctx;
|
||||||
|
|
||||||
if (!(proc->procgroup->capabilities & PROC_CAP_TERMINAL))
|
if (!(proc->procgroup->capabilities & PROC_CAP_TERMINAL))
|
||||||
return -ST_PERMISSION_ERROR;
|
return -ST_PERMISSION_ERROR;
|
||||||
@@ -52,3 +52,15 @@ int terminal_putstr (struct device* device, struct proc* proc, struct reschedule
|
|||||||
|
|
||||||
return ST_OK;
|
return ST_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int terminal_dimensions (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||||
|
void* a1, void* a2, void* a3, void* a4) {
|
||||||
|
(void)proc, (void)rctx, (void)a3, (void)a4, (void)device;
|
||||||
|
|
||||||
|
if (a1 == NULL || a2 == NULL)
|
||||||
|
return -ST_BAD_ADDRESS_SPACE;
|
||||||
|
|
||||||
|
flanterm_get_dimensions (ft_ctx, (size_t*)a1, (size_t*)a2);
|
||||||
|
|
||||||
|
return ST_OK;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,4 +16,7 @@ void terminal_fini (struct device* device);
|
|||||||
int terminal_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
int terminal_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||||
void* a1, void* a2, void* a3, void* a4);
|
void* a1, void* a2, void* a3, void* a4);
|
||||||
|
|
||||||
|
int terminal_dimensions (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||||
|
void* a1, void* a2, void* a3, void* a4);
|
||||||
|
|
||||||
#endif // _KERNEL_DEVICE_TERMINAL_H
|
#endif // _KERNEL_DEVICE_TERMINAL_H
|
||||||
|
|||||||
@@ -273,6 +273,11 @@ DEFINE_SYSCALL (sys_device_do) {
|
|||||||
|
|
||||||
spin_lock (&device->lock);
|
spin_lock (&device->lock);
|
||||||
|
|
||||||
|
if (device->ops[cmd] == NULL) {
|
||||||
|
spin_unlock (&device->lock);
|
||||||
|
return SYSRESULT (-ST_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
int ret = device_op (device, cmd, proc, rctx, ka1, ka2, ka3, ka4);
|
int ret = device_op (device, cmd, proc, rctx, ka1, ka2, ka3, ka4);
|
||||||
|
|
||||||
spin_unlock (&device->lock);
|
spin_unlock (&device->lock);
|
||||||
|
|||||||
@@ -5,3 +5,7 @@
|
|||||||
void terminal_print (const char* string, size_t len) {
|
void terminal_print (const char* string, size_t len) {
|
||||||
device_do ("TERMINAL", TERMINAL_PUTSTR, (void*)string, &len, NULL, NULL);
|
device_do ("TERMINAL", TERMINAL_PUTSTR, (void*)string, &len, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void terminal_dimensions (size_t* cols, size_t* rows) {
|
||||||
|
device_do ("TERMINAL", TERMINAL_DIMENSIONS, (void*)cols, (void*)rows, NULL, NULL);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,4 +7,7 @@
|
|||||||
/* Print a string onto a graphical terminal. Prints len chars */
|
/* Print a string onto a graphical terminal. Prints len chars */
|
||||||
void terminal_print (const char* string, size_t len);
|
void terminal_print (const char* string, size_t len);
|
||||||
|
|
||||||
|
/* Get terminal dimensions */
|
||||||
|
void terminal_dimensions (size_t* cols, size_t* rows);
|
||||||
|
|
||||||
#endif // _LIBTERMINAL_TERMINAL_TERMINAL_H
|
#endif // _LIBTERMINAL_TERMINAL_TERMINAL_H
|
||||||
|
|||||||
Reference in New Issue
Block a user