summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-18 03:08:58 -0400
committerIan Moffett <ian@osmora.org>2025-07-18 03:08:58 -0400
commit031217715fdd68556ffab79e9b898d9f8f80f035 (patch)
tree819b266a2f626f5c09921dc6919ff62fce691f57
parent96580ab98fdc1eee2b93f7ad021f70f7cb746d10 (diff)
usr: nerve: Add 'peek' verb to nerve(1)expt
While poking at a nerve can be very useful, there are times where we need to peek at them to see their current state. This commit introduces the 'peek' verb to do exactly that. Here is how one may peek at the console features: -- [chloe::osmora]~ nerve peek consfeat ansi_esc=1 show_curs=1 -- Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--share/man/man1/nerve.118
-rw-r--r--usr.bin/nerve/nerve.c67
2 files changed, 81 insertions, 4 deletions
diff --git a/share/man/man1/nerve.1 b/share/man/man1/nerve.1
index e15a9fd..8f2d19e 100644
--- a/share/man/man1/nerve.1
+++ b/share/man/man1/nerve.1
@@ -34,7 +34,9 @@ nerve <verb> [ .. payload for pokes ..]
verb 'poke': Poke a nerve
-nerve ending 'consattr': Console attributes <x, y>
+verb 'peek': Peek at a nerve
+
+nerve ending 'consattr': Console attributes
nerve ending 'consfeat': Console features
@@ -53,5 +55,19 @@ nerve poke consattr 0 0
verb nerve [x] [y]
.Ed
+A nerve may also be peeked at by using the 'peek' verb. Here is an example of the usage
+of this verb:
+
+.Bd -literal
+nerve peek consfeat
+ / /
+ verb nerve
+
+output:
+ ansi_esc=1
+ show_curs=0
+ ...
+.Ed
+
.Sh AUTHORS
.An Ian Moffett Aq Mt ian@osmora.org
diff --git a/usr.bin/nerve/nerve.c b/usr.bin/nerve/nerve.c
index a2a95fc..75a19be 100644
--- a/usr.bin/nerve/nerve.c
+++ b/usr.bin/nerve/nerve.c
@@ -38,9 +38,11 @@
/* Verb numeric defs (see string defs) */
#define VERB_UNKNOWN -1
#define VERB_POKE 0x0000
+#define VERB_PEEK 0x0001
/* Verb string defs (see numeric defs) */
#define SVERB_POKE "poke"
+#define SVERB_PEEK "peek"
/* Nerve numeric defs (see string defs) */
#define NERVE_UNKNOWN -1
@@ -57,6 +59,7 @@
struct verb_handler;
static int poke_nerve(const char *nerve, struct verb_handler *h);
+static int peek_nerve(const char *nerve, struct verb_handler *h);
static int nerve_to_def(const char *nerve);
/*
@@ -94,7 +97,8 @@ struct nerve_payload {
* its respective handler is called.
*/
static struct verb_handler verbtab[] = {
- { poke_nerve }
+ { poke_nerve },
+ { peek_nerve }
};
/*
@@ -153,6 +157,62 @@ get_nerve_payload(int argc, char *argv[], struct nerve_payload *res)
}
/*
+ * Peek at a control nerve located in /ctl/
+ *
+ * @nerve: Name of nerve to peek at
+ * @h: Verb handler, instance of self
+ *
+ * Returns less than zero if the nerve does
+ * not match.
+ */
+static int
+peek_nerve(const char *nerve, struct verb_handler *h)
+{
+ int error, nerve_idx = -1;
+
+ if (nerve == NULL || h == NULL) {
+ return -EINVAL;
+ }
+
+ /* Grab the nerve table index */
+ nerve_idx = nerve_to_def(nerve);
+ if (nerve_idx == NERVE_UNKNOWN) {
+ printf("[&^]: This is not my nerve.\n");
+ return -1;
+ }
+
+ switch (nerve_idx) {
+ case NERVE_CONSATTR:
+ {
+ struct console_attr c;
+ int fd;
+
+ fd = open("/ctl/console/attr", O_RDONLY);
+ read(fd, &c, sizeof(c));
+ printf("(cursx=%d, cursy=%d)\n", c.cursor_x, c.cursor_y);
+ close(fd);
+ break;
+ }
+ case NERVE_CONSFEAT:
+ {
+ struct console_feat f;
+ int fd;
+
+ fd = open("/ctl/console/feat", O_RDONLY);
+ read(fd, &f, sizeof(f));
+ printf("ansi_esc=%d\n", f.ansi_esc);
+ printf("show_curs=%d\n", f.show_curs);
+ close(fd);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/*
* Poke a control nerve located in /ctl/
*
* @nerve: Name of the nerve (e.g., consattr)
@@ -262,8 +322,6 @@ verb_to_def(const char *verb)
* Parse the verb and try to match it against
* a constant.
*
- * TODO: Add 'peek'
- *
* XXX: Here we are first matching the first character
* before we match the entire verb as that is more
* efficient than scanning each entire string until
@@ -274,6 +332,9 @@ verb_to_def(const char *verb)
if (strcmp(verb, SVERB_POKE) == 0) {
return VERB_POKE;
}
+ if (strcmp(verb, SVERB_PEEK) == 0) {
+ return VERB_PEEK;
+ }
default:
printf("[!] bad verb \"%s\"\n", verb);
return VERB_UNKNOWN;