Skip to content

Patches

ikozyris edited this page Sep 3, 2024 · 6 revisions

This page includes patches that some might find useful for customizing yocto beyond what the wizard script allows.

Disable unicode

For simplicity and performance, tested on commit 7617f6a

diff --git a/main.cpp b/main.cpp
index b205545..9ad818e 100755
--- a/main.cpp
+++ b/main.cpp
@@ -93,8 +93,8 @@ loop:
                print2header(tmp, 1);
                wmove(text_win, y, x);
 #endif
-               wget_wch(text_win, (wint_t*)s);
-               switch (s[0]) {
+               ch = wgetch(text_win);
+               switch (ch) {
                case DOWN:
                        if (ry >= curnum) // do not scroll indefinetly
                                break;
@@ -284,12 +284,9 @@ loop:
                default:
                        if (s[0] > 0 && s[0] < 32) // not a character
                                break;
-                       wins_nwstr(text_win, s, 1);
-                       wmove(text_win, y, x + 1);
-                       len = wcstombs(s2, s, 4);
-                       insert_s(*it, rx, s2, len);
-                       if (len > 1)
-                               ofx += len - 1; // Unicode character
+                       winsch(text_win, ch);
+                       insert_c(*it, x, ch);
+                       wmove(text_win, y, x+1);
                        break;
diff --git a/headers/gapbuffer.hpp b/headers/gapbuffer.hpp
index 8f796e2..6938556 100644
--- a/headers/gapbuffer.hpp
+++ b/headers/gapbuffer.hpp
@@ -1,7 +1,5 @@
 #include "headers.h"
 
-long signed ofx;
-
 #if defined(DEBUG)
 #define gap 2
 #define array_size 8
@@ -143,25 +140,17 @@ void apnd_s(gap_buf &a, const char *str)
 
 inline void eras(gap_buf &a)
 {
-       if (a[a.gps - 1] < 0) { // unicode
-               --a.gps;
-               --a.len;
-               --ofx;
-       }
        --a.gps;
        --a.len;
-       
 }

Logging function

useful for debbuging

void log(const char *str, ...)
{
	FILE *logfile = fopen("/tmp/yocto-log.log", "a");
	va_list args;
	va_start(args, str);
	vfprintf(logfile, str, args);
	va_end(args);
	fclose(logfile);
}

Line numbering

Line numbering is on by default (because I like it), with 3 digits, and one more for overflows (second image) This patch increases the digits to 5+1. Tested on commit 7e416f0

diff --git a/main.cpp b/main.cpp
index 4ca1ce2..5857f57 100755
--- a/main.cpp
+++ b/main.cpp
@@ -104,7 +105,7 @@ loop:
                                ofy++;
                                wscrl(text_win, 1);
                                wscrl(ln_win, 1);
-                               mvwprintw(ln_win, maxy - 1, 0, "%3d", ry + 2);
+                               mvwprintw(ln_win, maxy - 1, 0, "%5d", ry + 2);
                                wrefresh(ln_win);
                                wmove(text_win, y, 0);
                                print_line(*it);
@@ -121,7 +122,7 @@ loop:
                        if (y == 0 && ofy != 0) {
                                wscrl(text_win, -1); // scroll up
                                wscrl(ln_win, -1);
-                               mvwprintw(ln_win, 0, 0, "%3d", ry);
+                               mvwprintw(ln_win, 0, 0, "%5d", ry);
                                --ofy;
                                wmove(text_win, 0, 0);
                                --it; // why can't *(--it) work?
diff --git a/utils/init.c b/utils/init.c
index 45ecf38..3ac4a12 100644
--- a/utils/init.c
+++ b/utils/init.c
@@ -22,7 +22,7 @@ void init_curses()
 
 void init_text()
 {
-       text_win = newwin(maxy - 1, maxx - 4, 1, 4);
+       text_win = newwin(maxy - 1, maxx - 6, 1, 6);
        scrollok(text_win, TRUE);
        keypad(text_win, TRUE);
        wmove(text_win, 0, 0);
@@ -32,13 +32,13 @@ void print_lines()
 {
        short i = maxy;
        do
-               mvwprintw(ln_win, i - 1, 0, "%3ld", i + ofy);
+               mvwprintw(ln_win, i - 1, 0, "%5ld", i + ofy);
        while (--i != 0);
 }
 
 void init_lines()
 {
-       ln_win = newwin(maxy, 4, 1, 0);
+       ln_win = newwin(maxy, 6, 1, 0);
        wmove(ln_win, 0, 0);
        wattrset(ln_win, A_DIM);
        scrollok(ln_win, TRUE);

before

image image

after

image image

Clone this wiki locally