aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorne_mene <[email protected]>2026-03-01 15:54:19 +0100
committerne_mene <[email protected]>2026-03-01 15:54:19 +0100
commit915b623c32d3edb881d248153706338e7ae9054c (patch)
treee48e5d607ef4e1904da76f4cf86bd8a61f476250 /src
parent41175c11234c0a2a83257beb86694f3af129a689 (diff)
create, layout and example bar
Diffstat (limited to 'src')
-rw-r--r--src/bardata.c79
-rw-r--r--src/bardata.h8
-rw-r--r--src/pipe.c19
-rw-r--r--src/pipe.h4
4 files changed, 105 insertions, 5 deletions
diff --git a/src/bardata.c b/src/bardata.c
new file mode 100644
index 0000000..a35f3b5
--- /dev/null
+++ b/src/bardata.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "bardata.h"
+#include "pipe.h"
+
+typedef enum {
+ SIDE_LEFT,
+ SIDE_CENTER,
+ SIDE_RIGHT,
+} comp_side_t;
+
+typedef struct {
+} color_t;
+
+typedef struct {
+ char name[16];
+ char data[64];
+ color_t fg, bg;
+} comp_t;
+
+// Global state, oh naur D:
+comp_t comps[32];
+size_t comps_size = 0;
+comp_t *comps_left[16], *comps_right[16], *comps_center[16];
+size_t left_size = 0, right_size = 0, center_size = 0;
+
+void new_component(char *name) {
+ strcpy(comps[comps_size].name, name);
+ comps_size++;
+}
+
+comp_t *find_comp(char *name) {
+ for (size_t i = 0; i < comps_size; i++) {
+ if (strcmp(comps[i].name, name) == 0) {
+ return &comps[i];
+ }
+ }
+ return NULL;
+}
+
+void add_component(comp_side_t side, char *name) {
+ comp_t *comp = find_comp(name);
+ if (side == SIDE_LEFT) {
+ comps_left[left_size] = comp;
+ left_size++;
+ return;
+ }
+ if (side == SIDE_RIGHT) {
+ comps_right[right_size] = comp;
+ right_size++;
+ return;
+ }
+ if (side == SIDE_CENTER) {
+ comps_center[center_size] = comp;
+ center_size++;
+ return;
+ }
+}
+
+void set_layout(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
+ comp_side_t side = SIDE_LEFT;
+
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-left") == 0) {
+ side = SIDE_LEFT;
+ continue;
+ }
+ if (strcmp(argv[i], "-center") == 0) {
+ side = SIDE_CENTER;
+ continue;
+ }
+ if (strcmp(argv[i], "-right") == 0) {
+ side = SIDE_RIGHT;
+ continue;
+ }
+ add_component(side, argv[i]);
+ }
+}
diff --git a/src/bardata.h b/src/bardata.h
new file mode 100644
index 0000000..0c4028b
--- /dev/null
+++ b/src/bardata.h
@@ -0,0 +1,8 @@
+#ifndef BAR_H
+#define BAR_H
+#include "pipe.h"
+
+void new_component(char *name);
+void set_layout(char argv[MAX_ARGS][MAX_ARG_LEN], int argc);
+
+#endif
diff --git a/src/pipe.c b/src/pipe.c
index 88006a4..edce5de 100644
--- a/src/pipe.c
+++ b/src/pipe.c
@@ -1,10 +1,14 @@
-#include "pipe.h"
+
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <string.h>
#include <ctype.h>
+#include "pipe.h"
+#include "bardata.h"
+
FILE *named_pipe;
void init_pipe() {
@@ -25,9 +29,9 @@ void await_change() {
printf("Received: %s\n", buff);
int argc = 0, chr_on = 0, i = 0;
- char argv[4][256];
+ char argv[MAX_ARGS][MAX_ARG_LEN];
- while (argc < 4) {
+ while (argc < MAX_ARGS) {
char chr = buff[i];
if (chr == '\0') {
break;
@@ -58,4 +62,13 @@ void make_change(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
for (int i = 0; i < argc; i++) {
printf("Arg %d: %s\n", i + 1, argv[i]);
}
+
+ char *cmd = argv[0];
+ if (strcmp(cmd, "create") == 0) {
+ new_component(argv[1]);
+ return;
+ }
+ if (strcmp(cmd, "layout") == 0) {
+ set_layout(argv, argc);
+ }
}
diff --git a/src/pipe.h b/src/pipe.h
index 3f81432..e0e6301 100644
--- a/src/pipe.h
+++ b/src/pipe.h
@@ -3,8 +3,8 @@
#include <stdio.h>
#define PIPE_PATH "/tmp/tsarc.pipe"
-#define MAX_ARG_LEN 256
-#define MAX_ARGS 4
+#define MAX_ARG_LEN 128
+#define MAX_ARGS 16
void init_pipe();
void await_change();