Compare commits
1 Commits
patch-colo
...
patch-scro
Author | SHA1 | Date | |
---|---|---|---|
cfffa84142 |
114
config.def.h
114
config.def.h
@ -93,87 +93,46 @@ char *termname = "st-256color";
|
|||||||
*/
|
*/
|
||||||
unsigned int tabspaces = 8;
|
unsigned int tabspaces = 8;
|
||||||
|
|
||||||
typedef struct {
|
/* Terminal colors (16 first used in escape sequence) */
|
||||||
const char* const colors[258]; /* terminal colors */
|
static const char *colorname[] = {
|
||||||
unsigned int fg; /* foreground */
|
/* 8 normal colors */
|
||||||
unsigned int bg; /* background */
|
"black",
|
||||||
unsigned int cs; /* cursor */
|
"red3",
|
||||||
unsigned int rcs; /* reverse cursor */
|
"green3",
|
||||||
} ColorScheme;
|
"yellow3",
|
||||||
/*
|
"blue2",
|
||||||
* Terminal colors (16 first used in escape sequence,
|
"magenta3",
|
||||||
* 2 last for custom cursor color),
|
"cyan3",
|
||||||
* foreground, background, cursor, reverse cursor
|
"gray90",
|
||||||
*/
|
|
||||||
static const ColorScheme schemes[] = {
|
|
||||||
// st (dark)
|
|
||||||
{{"black", "red3", "green3", "yellow3",
|
|
||||||
"blue2", "magenta3", "cyan3", "gray90",
|
|
||||||
"gray50", "red", "green", "yellow",
|
|
||||||
"#5c5cff", "magenta", "cyan", "white",
|
|
||||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
|
|
||||||
// Alacritty (dark)
|
/* 8 bright colors */
|
||||||
{{"#1d1f21", "#cc6666", "#b5bd68", "#f0c674",
|
"gray50",
|
||||||
"#81a2be", "#b294bb", "#8abeb7", "#c5c8c6",
|
"red",
|
||||||
"#666666", "#d54e53", "#b9ca4a", "#e7c547",
|
"green",
|
||||||
"#7aa6da", "#c397d8", "#70c0b1", "#eaeaea",
|
"yellow",
|
||||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
"#5c5cff",
|
||||||
|
"magenta",
|
||||||
|
"cyan",
|
||||||
|
"white",
|
||||||
|
|
||||||
// One Half dark
|
[255] = 0,
|
||||||
{{"#282c34", "#e06c75", "#98c379", "#e5c07b",
|
|
||||||
"#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
|
||||||
"#282c34", "#e06c75", "#98c379", "#e5c07b",
|
|
||||||
"#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
|
||||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
|
|
||||||
// One Half light
|
/* more colors can be added after 255 to use with DefaultXX */
|
||||||
{{"#fafafa", "#e45649", "#50a14f", "#c18401",
|
"#cccccc",
|
||||||
"#0184bc", "#a626a4", "#0997b3", "#383a42",
|
"#555555",
|
||||||
"#fafafa", "#e45649", "#50a14f", "#c18401",
|
"gray90", /* default foreground colour */
|
||||||
"#0184bc", "#a626a4", "#0997b3", "#383a42",
|
"black", /* default background colour */
|
||||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
|
|
||||||
// Solarized dark
|
|
||||||
{{"#073642", "#dc322f", "#859900", "#b58900",
|
|
||||||
"#268bd2", "#d33682", "#2aa198", "#eee8d5",
|
|
||||||
"#002b36", "#cb4b16", "#586e75", "#657b83",
|
|
||||||
"#839496", "#6c71c4", "#93a1a1", "#fdf6e3",
|
|
||||||
[256]="#93a1a1", "#fdf6e3"}, 12, 8, 256, 257},
|
|
||||||
|
|
||||||
// Solarized light
|
|
||||||
{{"#eee8d5", "#dc322f", "#859900", "#b58900",
|
|
||||||
"#268bd2", "#d33682", "#2aa198", "#073642",
|
|
||||||
"#fdf6e3", "#cb4b16", "#93a1a1", "#839496",
|
|
||||||
"#657b83", "#6c71c4", "#586e75", "#002b36",
|
|
||||||
[256]="#586e75", "#002b36"}, 12, 8, 256, 257},
|
|
||||||
|
|
||||||
// Gruvbox dark
|
|
||||||
{{"#282828", "#cc241d", "#98971a", "#d79921",
|
|
||||||
"#458588", "#b16286", "#689d6a", "#a89984",
|
|
||||||
"#928374", "#fb4934", "#b8bb26", "#fabd2f",
|
|
||||||
"#83a598", "#d3869b", "#8ec07c", "#ebdbb2",
|
|
||||||
[256]="#ebdbb2", "#555555"}, 15, 0, 256, 257},
|
|
||||||
|
|
||||||
// Gruvbox light
|
|
||||||
{{"#fbf1c7", "#cc241d", "#98971a", "#d79921",
|
|
||||||
"#458588", "#b16286", "#689d6a", "#7c6f64",
|
|
||||||
"#928374", "#9d0006", "#79740e", "#b57614",
|
|
||||||
"#076678", "#8f3f71", "#427b58", "#3c3836",
|
|
||||||
[256]="#3c3836", "#555555"}, 15, 0, 256, 257},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const * colorname;
|
|
||||||
int colorscheme = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default colors (colorname index)
|
* Default colors (colorname index)
|
||||||
* foreground, background, cursor, reverse cursor
|
* foreground, background, cursor, reverse cursor
|
||||||
*/
|
*/
|
||||||
unsigned int defaultfg;
|
unsigned int defaultfg = 258;
|
||||||
unsigned int defaultbg;
|
unsigned int defaultbg = 259;
|
||||||
unsigned int defaultcs;
|
unsigned int defaultcs = 256;
|
||||||
static unsigned int defaultrcs;
|
static unsigned int defaultrcs = 257;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default shape of cursor
|
* Default shape of cursor
|
||||||
@ -242,17 +201,8 @@ static Shortcut shortcuts[] = {
|
|||||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||||
{ MODKEY, XK_1, selectscheme, {.i = 0} },
|
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
|
||||||
{ MODKEY, XK_2, selectscheme, {.i = 1} },
|
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
|
||||||
{ MODKEY, XK_3, selectscheme, {.i = 2} },
|
|
||||||
{ MODKEY, XK_4, selectscheme, {.i = 3} },
|
|
||||||
{ MODKEY, XK_5, selectscheme, {.i = 4} },
|
|
||||||
{ MODKEY, XK_6, selectscheme, {.i = 5} },
|
|
||||||
{ MODKEY, XK_7, selectscheme, {.i = 6} },
|
|
||||||
{ MODKEY, XK_8, selectscheme, {.i = 7} },
|
|
||||||
{ MODKEY, XK_9, selectscheme, {.i = 8} },
|
|
||||||
{ MODKEY, XK_0, nextscheme, {.i = +1} },
|
|
||||||
{ MODKEY|ControlMask, XK_0, nextscheme, {.i = -1} },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,306 +0,0 @@
|
|||||||
From 9bfbafa1e98c13c039bea4790941e51b3a8054b4 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Max Schillinger <maxschillinger@web.de>
|
|
||||||
Date: Thu, 23 Jun 2022 21:58:37 +0200
|
|
||||||
Subject: [PATCH] Add multiple color schemes and key bindings to change them
|
|
||||||
|
|
||||||
This commits adds these color schemes:
|
|
||||||
|
|
||||||
- the default (dark) st color scheme
|
|
||||||
- the default (dark) alacritty color scheme
|
|
||||||
- One Half (dark & light)
|
|
||||||
- Solarized (dark & light)
|
|
||||||
- Gruvbox (dark & light)
|
|
||||||
|
|
||||||
Select one with Alt+1..8.
|
|
||||||
Select the next one with Alt+0.
|
|
||||||
Select the previous one with Ctrl+Alt+0.
|
|
||||||
---
|
|
||||||
config.def.h | 118 +++++++++++++++++++++++++++++++++++++--------------
|
|
||||||
st.c | 22 ++++++++++
|
|
||||||
st.h | 2 +
|
|
||||||
x.c | 52 ++++++++++++++++++++++-
|
|
||||||
4 files changed, 160 insertions(+), 34 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/config.def.h b/config.def.h
|
|
||||||
index 91ab8ca..38777fe 100644
|
|
||||||
--- a/config.def.h
|
|
||||||
+++ b/config.def.h
|
|
||||||
@@ -93,46 +93,87 @@ char *termname = "st-256color";
|
|
||||||
*/
|
|
||||||
unsigned int tabspaces = 8;
|
|
||||||
|
|
||||||
-/* Terminal colors (16 first used in escape sequence) */
|
|
||||||
-static const char *colorname[] = {
|
|
||||||
- /* 8 normal colors */
|
|
||||||
- "black",
|
|
||||||
- "red3",
|
|
||||||
- "green3",
|
|
||||||
- "yellow3",
|
|
||||||
- "blue2",
|
|
||||||
- "magenta3",
|
|
||||||
- "cyan3",
|
|
||||||
- "gray90",
|
|
||||||
-
|
|
||||||
- /* 8 bright colors */
|
|
||||||
- "gray50",
|
|
||||||
- "red",
|
|
||||||
- "green",
|
|
||||||
- "yellow",
|
|
||||||
- "#5c5cff",
|
|
||||||
- "magenta",
|
|
||||||
- "cyan",
|
|
||||||
- "white",
|
|
||||||
-
|
|
||||||
- [255] = 0,
|
|
||||||
-
|
|
||||||
- /* more colors can be added after 255 to use with DefaultXX */
|
|
||||||
- "#cccccc",
|
|
||||||
- "#555555",
|
|
||||||
- "gray90", /* default foreground colour */
|
|
||||||
- "black", /* default background colour */
|
|
||||||
+typedef struct {
|
|
||||||
+ const char* const colors[258]; /* terminal colors */
|
|
||||||
+ unsigned int fg; /* foreground */
|
|
||||||
+ unsigned int bg; /* background */
|
|
||||||
+ unsigned int cs; /* cursor */
|
|
||||||
+ unsigned int rcs; /* reverse cursor */
|
|
||||||
+} ColorScheme;
|
|
||||||
+/*
|
|
||||||
+ * Terminal colors (16 first used in escape sequence,
|
|
||||||
+ * 2 last for custom cursor color),
|
|
||||||
+ * foreground, background, cursor, reverse cursor
|
|
||||||
+ */
|
|
||||||
+static const ColorScheme schemes[] = {
|
|
||||||
+ // st (dark)
|
|
||||||
+ {{"black", "red3", "green3", "yellow3",
|
|
||||||
+ "blue2", "magenta3", "cyan3", "gray90",
|
|
||||||
+ "gray50", "red", "green", "yellow",
|
|
||||||
+ "#5c5cff", "magenta", "cyan", "white",
|
|
||||||
+ [256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
+
|
|
||||||
+ // Alacritty (dark)
|
|
||||||
+ {{"#1d1f21", "#cc6666", "#b5bd68", "#f0c674",
|
|
||||||
+ "#81a2be", "#b294bb", "#8abeb7", "#c5c8c6",
|
|
||||||
+ "#666666", "#d54e53", "#b9ca4a", "#e7c547",
|
|
||||||
+ "#7aa6da", "#c397d8", "#70c0b1", "#eaeaea",
|
|
||||||
+ [256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
+
|
|
||||||
+ // One Half dark
|
|
||||||
+ {{"#282c34", "#e06c75", "#98c379", "#e5c07b",
|
|
||||||
+ "#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
|
||||||
+ "#282c34", "#e06c75", "#98c379", "#e5c07b",
|
|
||||||
+ "#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
|
||||||
+ [256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
+
|
|
||||||
+ // One Half light
|
|
||||||
+ {{"#fafafa", "#e45649", "#50a14f", "#c18401",
|
|
||||||
+ "#0184bc", "#a626a4", "#0997b3", "#383a42",
|
|
||||||
+ "#fafafa", "#e45649", "#50a14f", "#c18401",
|
|
||||||
+ "#0184bc", "#a626a4", "#0997b3", "#383a42",
|
|
||||||
+ [256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
|
||||||
+
|
|
||||||
+ // Solarized dark
|
|
||||||
+ {{"#073642", "#dc322f", "#859900", "#b58900",
|
|
||||||
+ "#268bd2", "#d33682", "#2aa198", "#eee8d5",
|
|
||||||
+ "#002b36", "#cb4b16", "#586e75", "#657b83",
|
|
||||||
+ "#839496", "#6c71c4", "#93a1a1", "#fdf6e3",
|
|
||||||
+ [256]="#93a1a1", "#fdf6e3"}, 12, 8, 256, 257},
|
|
||||||
+
|
|
||||||
+ // Solarized light
|
|
||||||
+ {{"#eee8d5", "#dc322f", "#859900", "#b58900",
|
|
||||||
+ "#268bd2", "#d33682", "#2aa198", "#073642",
|
|
||||||
+ "#fdf6e3", "#cb4b16", "#93a1a1", "#839496",
|
|
||||||
+ "#657b83", "#6c71c4", "#586e75", "#002b36",
|
|
||||||
+ [256]="#586e75", "#002b36"}, 12, 8, 256, 257},
|
|
||||||
+
|
|
||||||
+ // Gruvbox dark
|
|
||||||
+ {{"#282828", "#cc241d", "#98971a", "#d79921",
|
|
||||||
+ "#458588", "#b16286", "#689d6a", "#a89984",
|
|
||||||
+ "#928374", "#fb4934", "#b8bb26", "#fabd2f",
|
|
||||||
+ "#83a598", "#d3869b", "#8ec07c", "#ebdbb2",
|
|
||||||
+ [256]="#ebdbb2", "#555555"}, 15, 0, 256, 257},
|
|
||||||
+
|
|
||||||
+ // Gruvbox light
|
|
||||||
+ {{"#fbf1c7", "#cc241d", "#98971a", "#d79921",
|
|
||||||
+ "#458588", "#b16286", "#689d6a", "#7c6f64",
|
|
||||||
+ "#928374", "#9d0006", "#79740e", "#b57614",
|
|
||||||
+ "#076678", "#8f3f71", "#427b58", "#3c3836",
|
|
||||||
+ [256]="#3c3836", "#555555"}, 15, 0, 256, 257},
|
|
||||||
};
|
|
||||||
|
|
||||||
+static const char * const * colorname;
|
|
||||||
+int colorscheme = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Default colors (colorname index)
|
|
||||||
* foreground, background, cursor, reverse cursor
|
|
||||||
*/
|
|
||||||
-unsigned int defaultfg = 258;
|
|
||||||
-unsigned int defaultbg = 259;
|
|
||||||
-unsigned int defaultcs = 256;
|
|
||||||
-static unsigned int defaultrcs = 257;
|
|
||||||
+unsigned int defaultfg;
|
|
||||||
+unsigned int defaultbg;
|
|
||||||
+unsigned int defaultcs;
|
|
||||||
+static unsigned int defaultrcs;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Default shape of cursor
|
|
||||||
@@ -201,6 +242,17 @@ static Shortcut shortcuts[] = {
|
|
||||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
|
||||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
|
||||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
|
||||||
+ { MODKEY, XK_1, selectscheme, {.i = 0} },
|
|
||||||
+ { MODKEY, XK_2, selectscheme, {.i = 1} },
|
|
||||||
+ { MODKEY, XK_3, selectscheme, {.i = 2} },
|
|
||||||
+ { MODKEY, XK_4, selectscheme, {.i = 3} },
|
|
||||||
+ { MODKEY, XK_5, selectscheme, {.i = 4} },
|
|
||||||
+ { MODKEY, XK_6, selectscheme, {.i = 5} },
|
|
||||||
+ { MODKEY, XK_7, selectscheme, {.i = 6} },
|
|
||||||
+ { MODKEY, XK_8, selectscheme, {.i = 7} },
|
|
||||||
+ { MODKEY, XK_9, selectscheme, {.i = 8} },
|
|
||||||
+ { MODKEY, XK_0, nextscheme, {.i = +1} },
|
|
||||||
+ { MODKEY|ControlMask, XK_0, nextscheme, {.i = -1} },
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
diff --git a/st.c b/st.c
|
|
||||||
index 51049ba..3ffe333 100644
|
|
||||||
--- a/st.c
|
|
||||||
+++ b/st.c
|
|
||||||
@@ -2196,6 +2196,28 @@ tstrsequence(uchar c)
|
|
||||||
term.esc |= ESC_STR;
|
|
||||||
}
|
|
||||||
|
|
||||||
+void
|
|
||||||
+tupdatebgcolor(int oldbg, int newbg)
|
|
||||||
+{
|
|
||||||
+ for (int y = 0; y < term.row; y++) {
|
|
||||||
+ for (int x = 0; x < term.col; x++) {
|
|
||||||
+ if (term.line[y][x].bg == oldbg)
|
|
||||||
+ term.line[y][x].bg = newbg;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void
|
|
||||||
+tupdatefgcolor(int oldfg, int newfg)
|
|
||||||
+{
|
|
||||||
+ for (int y = 0; y < term.row; y++) {
|
|
||||||
+ for (int x = 0; x < term.col; x++) {
|
|
||||||
+ if (term.line[y][x].fg == oldfg)
|
|
||||||
+ term.line[y][x].fg = newfg;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
void
|
|
||||||
tcontrolcode(uchar ascii)
|
|
||||||
{
|
|
||||||
diff --git a/st.h b/st.h
|
|
||||||
index 519b9bd..2700de5 100644
|
|
||||||
--- a/st.h
|
|
||||||
+++ b/st.h
|
|
||||||
@@ -90,6 +90,8 @@ int tattrset(int);
|
|
||||||
void tnew(int, int);
|
|
||||||
void tresize(int, int);
|
|
||||||
void tsetdirtattr(int);
|
|
||||||
+void tupdatebgcolor(int, int);
|
|
||||||
+void tupdatefgcolor(int, int);
|
|
||||||
void ttyhangup(void);
|
|
||||||
int ttynew(const char *, char *, const char *, char **);
|
|
||||||
size_t ttyread(void);
|
|
||||||
diff --git a/x.c b/x.c
|
|
||||||
index 8a16faa..bc0a48c 100644
|
|
||||||
--- a/x.c
|
|
||||||
+++ b/x.c
|
|
||||||
@@ -59,6 +59,8 @@ static void zoom(const Arg *);
|
|
||||||
static void zoomabs(const Arg *);
|
|
||||||
static void zoomreset(const Arg *);
|
|
||||||
static void ttysend(const Arg *);
|
|
||||||
+static void nextscheme(const Arg *);
|
|
||||||
+static void selectscheme(const Arg *);
|
|
||||||
|
|
||||||
/* config.h for applying patches and the configuration. */
|
|
||||||
#include "config.h"
|
|
||||||
@@ -185,6 +187,7 @@ static void mousesel(XEvent *, int);
|
|
||||||
static void mousereport(XEvent *);
|
|
||||||
static char *kmap(KeySym, uint);
|
|
||||||
static int match(uint, uint);
|
|
||||||
+static void updatescheme(void);
|
|
||||||
|
|
||||||
static void run(void);
|
|
||||||
static void usage(void);
|
|
||||||
@@ -785,7 +788,7 @@ xloadcols(void)
|
|
||||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
|
||||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
|
||||||
} else {
|
|
||||||
- dc.collen = MAX(LEN(colorname), 256);
|
|
||||||
+ dc.collen = 258;
|
|
||||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -2008,6 +2011,47 @@ usage(void)
|
|
||||||
" [stty_args ...]\n", argv0, argv0);
|
|
||||||
}
|
|
||||||
|
|
||||||
+void
|
|
||||||
+nextscheme(const Arg *arg)
|
|
||||||
+{
|
|
||||||
+ colorscheme += arg->i;
|
|
||||||
+ if (colorscheme >= (int)LEN(schemes))
|
|
||||||
+ colorscheme = 0;
|
|
||||||
+ else if (colorscheme < 0)
|
|
||||||
+ colorscheme = LEN(schemes) - 1;
|
|
||||||
+ updatescheme();
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void
|
|
||||||
+selectscheme(const Arg *arg)
|
|
||||||
+{
|
|
||||||
+ if (BETWEEN(arg->i, 0, LEN(schemes)-1)) {
|
|
||||||
+ colorscheme = arg->i;
|
|
||||||
+ updatescheme();
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void
|
|
||||||
+updatescheme(void)
|
|
||||||
+{
|
|
||||||
+ int oldbg, oldfg;
|
|
||||||
+
|
|
||||||
+ oldbg = defaultbg;
|
|
||||||
+ oldfg = defaultfg;
|
|
||||||
+ colorname = schemes[colorscheme].colors;
|
|
||||||
+ defaultbg = schemes[colorscheme].bg;
|
|
||||||
+ defaultfg = schemes[colorscheme].fg;
|
|
||||||
+ defaultcs = schemes[colorscheme].cs;
|
|
||||||
+ defaultrcs = schemes[colorscheme].rcs;
|
|
||||||
+ xloadcols();
|
|
||||||
+ if (defaultbg != oldbg)
|
|
||||||
+ tupdatebgcolor(oldbg, defaultbg);
|
|
||||||
+ if (defaultfg != oldfg)
|
|
||||||
+ tupdatefgcolor(oldfg, defaultfg);
|
|
||||||
+ cresize(win.w, win.h);
|
|
||||||
+ redraw();
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
@@ -2060,6 +2104,12 @@ main(int argc, char *argv[])
|
|
||||||
} ARGEND;
|
|
||||||
|
|
||||||
run:
|
|
||||||
+ colorname = schemes[colorscheme].colors;
|
|
||||||
+ defaultbg = schemes[colorscheme].bg;
|
|
||||||
+ defaultfg = schemes[colorscheme].fg;
|
|
||||||
+ defaultcs = schemes[colorscheme].cs;
|
|
||||||
+ defaultrcs = schemes[colorscheme].rcs;
|
|
||||||
+
|
|
||||||
if (argc > 0) /* eat all remaining arguments */
|
|
||||||
opt_cmd = argv;
|
|
||||||
|
|
||||||
--
|
|
||||||
2.36.1
|
|
||||||
|
|
350
st-scrollback-0.8.5.diff
Normal file
350
st-scrollback-0.8.5.diff
Normal file
@ -0,0 +1,350 @@
|
|||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 91ab8ca..e3b469b 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -201,6 +201,8 @@ static Shortcut shortcuts[] = {
|
||||||
|
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||||
|
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||||
|
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||||
|
+ { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
|
||||||
|
+ { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
diff --git a/st.c b/st.c
|
||||||
|
index 51049ba..cd750f2 100644
|
||||||
|
--- a/st.c
|
||||||
|
+++ b/st.c
|
||||||
|
@@ -35,6 +35,7 @@
|
||||||
|
#define ESC_ARG_SIZ 16
|
||||||
|
#define STR_BUF_SIZ ESC_BUF_SIZ
|
||||||
|
#define STR_ARG_SIZ ESC_ARG_SIZ
|
||||||
|
+#define HISTSIZE 2000
|
||||||
|
|
||||||
|
/* macros */
|
||||||
|
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
||||||
|
@@ -42,6 +43,9 @@
|
||||||
|
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
||||||
|
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
||||||
|
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
||||||
|
+#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
|
||||||
|
+ term.scr + HISTSIZE + 1) % HISTSIZE] : \
|
||||||
|
+ term.line[(y) - term.scr])
|
||||||
|
|
||||||
|
enum term_mode {
|
||||||
|
MODE_WRAP = 1 << 0,
|
||||||
|
@@ -115,6 +119,9 @@ typedef struct {
|
||||||
|
int col; /* nb col */
|
||||||
|
Line *line; /* screen */
|
||||||
|
Line *alt; /* alternate screen */
|
||||||
|
+ Line hist[HISTSIZE]; /* history buffer */
|
||||||
|
+ int histi; /* history index */
|
||||||
|
+ int scr; /* scroll back */
|
||||||
|
int *dirty; /* dirtyness of lines */
|
||||||
|
TCursor c; /* cursor */
|
||||||
|
int ocx; /* old cursor col */
|
||||||
|
@@ -184,8 +191,8 @@ static void tnewline(int);
|
||||||
|
static void tputtab(int);
|
||||||
|
static void tputc(Rune);
|
||||||
|
static void treset(void);
|
||||||
|
-static void tscrollup(int, int);
|
||||||
|
-static void tscrolldown(int, int);
|
||||||
|
+static void tscrollup(int, int, int);
|
||||||
|
+static void tscrolldown(int, int, int);
|
||||||
|
static void tsetattr(const int *, int);
|
||||||
|
static void tsetchar(Rune, const Glyph *, int, int);
|
||||||
|
static void tsetdirt(int, int);
|
||||||
|
@@ -416,10 +423,10 @@ tlinelen(int y)
|
||||||
|
{
|
||||||
|
int i = term.col;
|
||||||
|
|
||||||
|
- if (term.line[y][i - 1].mode & ATTR_WRAP)
|
||||||
|
+ if (TLINE(y)[i - 1].mode & ATTR_WRAP)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
- while (i > 0 && term.line[y][i - 1].u == ' ')
|
||||||
|
+ while (i > 0 && TLINE(y)[i - 1].u == ' ')
|
||||||
|
--i;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
@@ -528,7 +535,7 @@ selsnap(int *x, int *y, int direction)
|
||||||
|
* Snap around if the word wraps around at the end or
|
||||||
|
* beginning of a line.
|
||||||
|
*/
|
||||||
|
- prevgp = &term.line[*y][*x];
|
||||||
|
+ prevgp = &TLINE(*y)[*x];
|
||||||
|
prevdelim = ISDELIM(prevgp->u);
|
||||||
|
for (;;) {
|
||||||
|
newx = *x + direction;
|
||||||
|
@@ -543,14 +550,14 @@ selsnap(int *x, int *y, int direction)
|
||||||
|
yt = *y, xt = *x;
|
||||||
|
else
|
||||||
|
yt = newy, xt = newx;
|
||||||
|
- if (!(term.line[yt][xt].mode & ATTR_WRAP))
|
||||||
|
+ if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newx >= tlinelen(newy))
|
||||||
|
break;
|
||||||
|
|
||||||
|
- gp = &term.line[newy][newx];
|
||||||
|
+ gp = &TLINE(newy)[newx];
|
||||||
|
delim = ISDELIM(gp->u);
|
||||||
|
if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
|
||||||
|
|| (delim && gp->u != prevgp->u)))
|
||||||
|
@@ -571,14 +578,14 @@ selsnap(int *x, int *y, int direction)
|
||||||
|
*x = (direction < 0) ? 0 : term.col - 1;
|
||||||
|
if (direction < 0) {
|
||||||
|
for (; *y > 0; *y += direction) {
|
||||||
|
- if (!(term.line[*y-1][term.col-1].mode
|
||||||
|
+ if (!(TLINE(*y-1)[term.col-1].mode
|
||||||
|
& ATTR_WRAP)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (direction > 0) {
|
||||||
|
for (; *y < term.row-1; *y += direction) {
|
||||||
|
- if (!(term.line[*y][term.col-1].mode
|
||||||
|
+ if (!(TLINE(*y)[term.col-1].mode
|
||||||
|
& ATTR_WRAP)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
@@ -609,13 +616,13 @@ getsel(void)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sel.type == SEL_RECTANGULAR) {
|
||||||
|
- gp = &term.line[y][sel.nb.x];
|
||||||
|
+ gp = &TLINE(y)[sel.nb.x];
|
||||||
|
lastx = sel.ne.x;
|
||||||
|
} else {
|
||||||
|
- gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
|
||||||
|
+ gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
|
||||||
|
lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
|
||||||
|
}
|
||||||
|
- last = &term.line[y][MIN(lastx, linelen-1)];
|
||||||
|
+ last = &TLINE(y)[MIN(lastx, linelen-1)];
|
||||||
|
while (last >= gp && last->u == ' ')
|
||||||
|
--last;
|
||||||
|
|
||||||
|
@@ -851,6 +858,9 @@ void
|
||||||
|
ttywrite(const char *s, size_t n, int may_echo)
|
||||||
|
{
|
||||||
|
const char *next;
|
||||||
|
+ Arg arg = (Arg) { .i = term.scr };
|
||||||
|
+
|
||||||
|
+ kscrolldown(&arg);
|
||||||
|
|
||||||
|
if (may_echo && IS_SET(MODE_ECHO))
|
||||||
|
twrite(s, n, 1);
|
||||||
|
@@ -1062,12 +1072,52 @@ tswapscreen(void)
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
-tscrolldown(int orig, int n)
|
||||||
|
+kscrolldown(const Arg* a)
|
||||||
|
+{
|
||||||
|
+ int n = a->i;
|
||||||
|
+
|
||||||
|
+ if (n < 0)
|
||||||
|
+ n = term.row + n;
|
||||||
|
+
|
||||||
|
+ if (n > term.scr)
|
||||||
|
+ n = term.scr;
|
||||||
|
+
|
||||||
|
+ if (term.scr > 0) {
|
||||||
|
+ term.scr -= n;
|
||||||
|
+ selscroll(0, -n);
|
||||||
|
+ tfulldirt();
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+kscrollup(const Arg* a)
|
||||||
|
+{
|
||||||
|
+ int n = a->i;
|
||||||
|
+
|
||||||
|
+ if (n < 0)
|
||||||
|
+ n = term.row + n;
|
||||||
|
+
|
||||||
|
+ if (term.scr <= HISTSIZE-n) {
|
||||||
|
+ term.scr += n;
|
||||||
|
+ selscroll(0, n);
|
||||||
|
+ tfulldirt();
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+tscrolldown(int orig, int n, int copyhist)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
Line temp;
|
||||||
|
|
||||||
|
LIMIT(n, 0, term.bot-orig+1);
|
||||||
|
+ if (copyhist) {
|
||||||
|
+ term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
|
||||||
|
+ temp = term.hist[term.histi];
|
||||||
|
+ term.hist[term.histi] = term.line[term.bot];
|
||||||
|
+ term.line[term.bot] = temp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
|
||||||
|
tsetdirt(orig, term.bot-n);
|
||||||
|
tclearregion(0, term.bot-n+1, term.col-1, term.bot);
|
||||||
|
@@ -1078,17 +1128,28 @@ tscrolldown(int orig, int n)
|
||||||
|
term.line[i-n] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
- selscroll(orig, n);
|
||||||
|
+ if (term.scr == 0)
|
||||||
|
+ selscroll(orig, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
-tscrollup(int orig, int n)
|
||||||
|
+tscrollup(int orig, int n, int copyhist)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
Line temp;
|
||||||
|
|
||||||
|
LIMIT(n, 0, term.bot-orig+1);
|
||||||
|
|
||||||
|
+ if (copyhist) {
|
||||||
|
+ term.histi = (term.histi + 1) % HISTSIZE;
|
||||||
|
+ temp = term.hist[term.histi];
|
||||||
|
+ term.hist[term.histi] = term.line[orig];
|
||||||
|
+ term.line[orig] = temp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (term.scr > 0 && term.scr < HISTSIZE)
|
||||||
|
+ term.scr = MIN(term.scr + n, HISTSIZE-1);
|
||||||
|
+
|
||||||
|
tclearregion(0, orig, term.col-1, orig+n-1);
|
||||||
|
tsetdirt(orig+n, term.bot);
|
||||||
|
|
||||||
|
@@ -1098,7 +1159,8 @@ tscrollup(int orig, int n)
|
||||||
|
term.line[i+n] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
- selscroll(orig, -n);
|
||||||
|
+ if (term.scr == 0)
|
||||||
|
+ selscroll(orig, -n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
@@ -1127,7 +1189,7 @@ tnewline(int first_col)
|
||||||
|
int y = term.c.y;
|
||||||
|
|
||||||
|
if (y == term.bot) {
|
||||||
|
- tscrollup(term.top, 1);
|
||||||
|
+ tscrollup(term.top, 1, 1);
|
||||||
|
} else {
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
@@ -1292,14 +1354,14 @@ void
|
||||||
|
tinsertblankline(int n)
|
||||||
|
{
|
||||||
|
if (BETWEEN(term.c.y, term.top, term.bot))
|
||||||
|
- tscrolldown(term.c.y, n);
|
||||||
|
+ tscrolldown(term.c.y, n, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tdeleteline(int n)
|
||||||
|
{
|
||||||
|
if (BETWEEN(term.c.y, term.top, term.bot))
|
||||||
|
- tscrollup(term.c.y, n);
|
||||||
|
+ tscrollup(term.c.y, n, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t
|
||||||
|
@@ -1736,11 +1798,11 @@ csihandle(void)
|
||||||
|
break;
|
||||||
|
case 'S': /* SU -- Scroll <n> line up */
|
||||||
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
|
- tscrollup(term.top, csiescseq.arg[0]);
|
||||||
|
+ tscrollup(term.top, csiescseq.arg[0], 0);
|
||||||
|
break;
|
||||||
|
case 'T': /* SD -- Scroll <n> line down */
|
||||||
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
|
- tscrolldown(term.top, csiescseq.arg[0]);
|
||||||
|
+ tscrolldown(term.top, csiescseq.arg[0], 0);
|
||||||
|
break;
|
||||||
|
case 'L': /* IL -- Insert <n> blank lines */
|
||||||
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
|
@@ -2330,7 +2392,7 @@ eschandle(uchar ascii)
|
||||||
|
return 0;
|
||||||
|
case 'D': /* IND -- Linefeed */
|
||||||
|
if (term.c.y == term.bot) {
|
||||||
|
- tscrollup(term.top, 1);
|
||||||
|
+ tscrollup(term.top, 1, 1);
|
||||||
|
} else {
|
||||||
|
tmoveto(term.c.x, term.c.y+1);
|
||||||
|
}
|
||||||
|
@@ -2343,7 +2405,7 @@ eschandle(uchar ascii)
|
||||||
|
break;
|
||||||
|
case 'M': /* RI -- Reverse index */
|
||||||
|
if (term.c.y == term.top) {
|
||||||
|
- tscrolldown(term.top, 1);
|
||||||
|
+ tscrolldown(term.top, 1, 1);
|
||||||
|
} else {
|
||||||
|
tmoveto(term.c.x, term.c.y-1);
|
||||||
|
}
|
||||||
|
@@ -2557,7 +2619,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
|
||||||
|
void
|
||||||
|
tresize(int col, int row)
|
||||||
|
{
|
||||||
|
- int i;
|
||||||
|
+ int i, j;
|
||||||
|
int minrow = MIN(row, term.row);
|
||||||
|
int mincol = MIN(col, term.col);
|
||||||
|
int *bp;
|
||||||
|
@@ -2594,6 +2656,14 @@ tresize(int col, int row)
|
||||||
|
term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
|
||||||
|
term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
|
||||||
|
|
||||||
|
+ for (i = 0; i < HISTSIZE; i++) {
|
||||||
|
+ term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
|
||||||
|
+ for (j = mincol; j < col; j++) {
|
||||||
|
+ term.hist[i][j] = term.c.attr;
|
||||||
|
+ term.hist[i][j].u = ' ';
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
/* resize each row to new width, zero-pad if needed */
|
||||||
|
for (i = 0; i < minrow; i++) {
|
||||||
|
term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
|
||||||
|
@@ -2652,7 +2722,7 @@ drawregion(int x1, int y1, int x2, int y2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
term.dirty[y] = 0;
|
||||||
|
- xdrawline(term.line[y], x1, y, x2);
|
||||||
|
+ xdrawline(TLINE(y), x1, y, x2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -2673,8 +2743,9 @@ draw(void)
|
||||||
|
cx--;
|
||||||
|
|
||||||
|
drawregion(0, 0, term.col, term.row);
|
||||||
|
- xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
||||||
|
- term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
|
+ if (term.scr == 0)
|
||||||
|
+ xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
||||||
|
+ term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
|
term.ocx = cx;
|
||||||
|
term.ocy = term.c.y;
|
||||||
|
xfinishdraw();
|
||||||
|
diff --git a/st.h b/st.h
|
||||||
|
index 519b9bd..da36b34 100644
|
||||||
|
--- a/st.h
|
||||||
|
+++ b/st.h
|
||||||
|
@@ -81,6 +81,8 @@ void die(const char *, ...);
|
||||||
|
void redraw(void);
|
||||||
|
void draw(void);
|
||||||
|
|
||||||
|
+void kscrolldown(const Arg *);
|
||||||
|
+void kscrollup(const Arg *);
|
||||||
|
void printscreen(const Arg *);
|
||||||
|
void printsel(const Arg *);
|
||||||
|
void sendbreak(const Arg *);
|
139
st.c
139
st.c
@ -35,6 +35,7 @@
|
|||||||
#define ESC_ARG_SIZ 16
|
#define ESC_ARG_SIZ 16
|
||||||
#define STR_BUF_SIZ ESC_BUF_SIZ
|
#define STR_BUF_SIZ ESC_BUF_SIZ
|
||||||
#define STR_ARG_SIZ ESC_ARG_SIZ
|
#define STR_ARG_SIZ ESC_ARG_SIZ
|
||||||
|
#define HISTSIZE 2000
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
||||||
@ -42,6 +43,9 @@
|
|||||||
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
||||||
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
||||||
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
||||||
|
#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
|
||||||
|
term.scr + HISTSIZE + 1) % HISTSIZE] : \
|
||||||
|
term.line[(y) - term.scr])
|
||||||
|
|
||||||
enum term_mode {
|
enum term_mode {
|
||||||
MODE_WRAP = 1 << 0,
|
MODE_WRAP = 1 << 0,
|
||||||
@ -115,6 +119,9 @@ typedef struct {
|
|||||||
int col; /* nb col */
|
int col; /* nb col */
|
||||||
Line *line; /* screen */
|
Line *line; /* screen */
|
||||||
Line *alt; /* alternate screen */
|
Line *alt; /* alternate screen */
|
||||||
|
Line hist[HISTSIZE]; /* history buffer */
|
||||||
|
int histi; /* history index */
|
||||||
|
int scr; /* scroll back */
|
||||||
int *dirty; /* dirtyness of lines */
|
int *dirty; /* dirtyness of lines */
|
||||||
TCursor c; /* cursor */
|
TCursor c; /* cursor */
|
||||||
int ocx; /* old cursor col */
|
int ocx; /* old cursor col */
|
||||||
@ -184,8 +191,8 @@ static void tnewline(int);
|
|||||||
static void tputtab(int);
|
static void tputtab(int);
|
||||||
static void tputc(Rune);
|
static void tputc(Rune);
|
||||||
static void treset(void);
|
static void treset(void);
|
||||||
static void tscrollup(int, int);
|
static void tscrollup(int, int, int);
|
||||||
static void tscrolldown(int, int);
|
static void tscrolldown(int, int, int);
|
||||||
static void tsetattr(const int *, int);
|
static void tsetattr(const int *, int);
|
||||||
static void tsetchar(Rune, const Glyph *, int, int);
|
static void tsetchar(Rune, const Glyph *, int, int);
|
||||||
static void tsetdirt(int, int);
|
static void tsetdirt(int, int);
|
||||||
@ -416,10 +423,10 @@ tlinelen(int y)
|
|||||||
{
|
{
|
||||||
int i = term.col;
|
int i = term.col;
|
||||||
|
|
||||||
if (term.line[y][i - 1].mode & ATTR_WRAP)
|
if (TLINE(y)[i - 1].mode & ATTR_WRAP)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
while (i > 0 && term.line[y][i - 1].u == ' ')
|
while (i > 0 && TLINE(y)[i - 1].u == ' ')
|
||||||
--i;
|
--i;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
@ -528,7 +535,7 @@ selsnap(int *x, int *y, int direction)
|
|||||||
* Snap around if the word wraps around at the end or
|
* Snap around if the word wraps around at the end or
|
||||||
* beginning of a line.
|
* beginning of a line.
|
||||||
*/
|
*/
|
||||||
prevgp = &term.line[*y][*x];
|
prevgp = &TLINE(*y)[*x];
|
||||||
prevdelim = ISDELIM(prevgp->u);
|
prevdelim = ISDELIM(prevgp->u);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
newx = *x + direction;
|
newx = *x + direction;
|
||||||
@ -543,14 +550,14 @@ selsnap(int *x, int *y, int direction)
|
|||||||
yt = *y, xt = *x;
|
yt = *y, xt = *x;
|
||||||
else
|
else
|
||||||
yt = newy, xt = newx;
|
yt = newy, xt = newx;
|
||||||
if (!(term.line[yt][xt].mode & ATTR_WRAP))
|
if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newx >= tlinelen(newy))
|
if (newx >= tlinelen(newy))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
gp = &term.line[newy][newx];
|
gp = &TLINE(newy)[newx];
|
||||||
delim = ISDELIM(gp->u);
|
delim = ISDELIM(gp->u);
|
||||||
if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
|
if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
|
||||||
|| (delim && gp->u != prevgp->u)))
|
|| (delim && gp->u != prevgp->u)))
|
||||||
@ -571,14 +578,14 @@ selsnap(int *x, int *y, int direction)
|
|||||||
*x = (direction < 0) ? 0 : term.col - 1;
|
*x = (direction < 0) ? 0 : term.col - 1;
|
||||||
if (direction < 0) {
|
if (direction < 0) {
|
||||||
for (; *y > 0; *y += direction) {
|
for (; *y > 0; *y += direction) {
|
||||||
if (!(term.line[*y-1][term.col-1].mode
|
if (!(TLINE(*y-1)[term.col-1].mode
|
||||||
& ATTR_WRAP)) {
|
& ATTR_WRAP)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (direction > 0) {
|
} else if (direction > 0) {
|
||||||
for (; *y < term.row-1; *y += direction) {
|
for (; *y < term.row-1; *y += direction) {
|
||||||
if (!(term.line[*y][term.col-1].mode
|
if (!(TLINE(*y)[term.col-1].mode
|
||||||
& ATTR_WRAP)) {
|
& ATTR_WRAP)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -609,13 +616,13 @@ getsel(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sel.type == SEL_RECTANGULAR) {
|
if (sel.type == SEL_RECTANGULAR) {
|
||||||
gp = &term.line[y][sel.nb.x];
|
gp = &TLINE(y)[sel.nb.x];
|
||||||
lastx = sel.ne.x;
|
lastx = sel.ne.x;
|
||||||
} else {
|
} else {
|
||||||
gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
|
gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
|
||||||
lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
|
lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
|
||||||
}
|
}
|
||||||
last = &term.line[y][MIN(lastx, linelen-1)];
|
last = &TLINE(y)[MIN(lastx, linelen-1)];
|
||||||
while (last >= gp && last->u == ' ')
|
while (last >= gp && last->u == ' ')
|
||||||
--last;
|
--last;
|
||||||
|
|
||||||
@ -851,6 +858,9 @@ void
|
|||||||
ttywrite(const char *s, size_t n, int may_echo)
|
ttywrite(const char *s, size_t n, int may_echo)
|
||||||
{
|
{
|
||||||
const char *next;
|
const char *next;
|
||||||
|
Arg arg = (Arg) { .i = term.scr };
|
||||||
|
|
||||||
|
kscrolldown(&arg);
|
||||||
|
|
||||||
if (may_echo && IS_SET(MODE_ECHO))
|
if (may_echo && IS_SET(MODE_ECHO))
|
||||||
twrite(s, n, 1);
|
twrite(s, n, 1);
|
||||||
@ -1062,12 +1072,52 @@ tswapscreen(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tscrolldown(int orig, int n)
|
kscrolldown(const Arg* a)
|
||||||
|
{
|
||||||
|
int n = a->i;
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
|
n = term.row + n;
|
||||||
|
|
||||||
|
if (n > term.scr)
|
||||||
|
n = term.scr;
|
||||||
|
|
||||||
|
if (term.scr > 0) {
|
||||||
|
term.scr -= n;
|
||||||
|
selscroll(0, -n);
|
||||||
|
tfulldirt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kscrollup(const Arg* a)
|
||||||
|
{
|
||||||
|
int n = a->i;
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
|
n = term.row + n;
|
||||||
|
|
||||||
|
if (term.scr <= HISTSIZE-n) {
|
||||||
|
term.scr += n;
|
||||||
|
selscroll(0, n);
|
||||||
|
tfulldirt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tscrolldown(int orig, int n, int copyhist)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Line temp;
|
Line temp;
|
||||||
|
|
||||||
LIMIT(n, 0, term.bot-orig+1);
|
LIMIT(n, 0, term.bot-orig+1);
|
||||||
|
if (copyhist) {
|
||||||
|
term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
|
||||||
|
temp = term.hist[term.histi];
|
||||||
|
term.hist[term.histi] = term.line[term.bot];
|
||||||
|
term.line[term.bot] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tsetdirt(orig, term.bot-n);
|
tsetdirt(orig, term.bot-n);
|
||||||
tclearregion(0, term.bot-n+1, term.col-1, term.bot);
|
tclearregion(0, term.bot-n+1, term.col-1, term.bot);
|
||||||
@ -1078,17 +1128,28 @@ tscrolldown(int orig, int n)
|
|||||||
term.line[i-n] = temp;
|
term.line[i-n] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (term.scr == 0)
|
||||||
selscroll(orig, n);
|
selscroll(orig, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tscrollup(int orig, int n)
|
tscrollup(int orig, int n, int copyhist)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Line temp;
|
Line temp;
|
||||||
|
|
||||||
LIMIT(n, 0, term.bot-orig+1);
|
LIMIT(n, 0, term.bot-orig+1);
|
||||||
|
|
||||||
|
if (copyhist) {
|
||||||
|
term.histi = (term.histi + 1) % HISTSIZE;
|
||||||
|
temp = term.hist[term.histi];
|
||||||
|
term.hist[term.histi] = term.line[orig];
|
||||||
|
term.line[orig] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (term.scr > 0 && term.scr < HISTSIZE)
|
||||||
|
term.scr = MIN(term.scr + n, HISTSIZE-1);
|
||||||
|
|
||||||
tclearregion(0, orig, term.col-1, orig+n-1);
|
tclearregion(0, orig, term.col-1, orig+n-1);
|
||||||
tsetdirt(orig+n, term.bot);
|
tsetdirt(orig+n, term.bot);
|
||||||
|
|
||||||
@ -1098,6 +1159,7 @@ tscrollup(int orig, int n)
|
|||||||
term.line[i+n] = temp;
|
term.line[i+n] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (term.scr == 0)
|
||||||
selscroll(orig, -n);
|
selscroll(orig, -n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1127,7 +1189,7 @@ tnewline(int first_col)
|
|||||||
int y = term.c.y;
|
int y = term.c.y;
|
||||||
|
|
||||||
if (y == term.bot) {
|
if (y == term.bot) {
|
||||||
tscrollup(term.top, 1);
|
tscrollup(term.top, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
@ -1292,14 +1354,14 @@ void
|
|||||||
tinsertblankline(int n)
|
tinsertblankline(int n)
|
||||||
{
|
{
|
||||||
if (BETWEEN(term.c.y, term.top, term.bot))
|
if (BETWEEN(term.c.y, term.top, term.bot))
|
||||||
tscrolldown(term.c.y, n);
|
tscrolldown(term.c.y, n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tdeleteline(int n)
|
tdeleteline(int n)
|
||||||
{
|
{
|
||||||
if (BETWEEN(term.c.y, term.top, term.bot))
|
if (BETWEEN(term.c.y, term.top, term.bot))
|
||||||
tscrollup(term.c.y, n);
|
tscrollup(term.c.y, n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t
|
int32_t
|
||||||
@ -1736,11 +1798,11 @@ csihandle(void)
|
|||||||
break;
|
break;
|
||||||
case 'S': /* SU -- Scroll <n> line up */
|
case 'S': /* SU -- Scroll <n> line up */
|
||||||
DEFAULT(csiescseq.arg[0], 1);
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
tscrollup(term.top, csiescseq.arg[0]);
|
tscrollup(term.top, csiescseq.arg[0], 0);
|
||||||
break;
|
break;
|
||||||
case 'T': /* SD -- Scroll <n> line down */
|
case 'T': /* SD -- Scroll <n> line down */
|
||||||
DEFAULT(csiescseq.arg[0], 1);
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
tscrolldown(term.top, csiescseq.arg[0]);
|
tscrolldown(term.top, csiescseq.arg[0], 0);
|
||||||
break;
|
break;
|
||||||
case 'L': /* IL -- Insert <n> blank lines */
|
case 'L': /* IL -- Insert <n> blank lines */
|
||||||
DEFAULT(csiescseq.arg[0], 1);
|
DEFAULT(csiescseq.arg[0], 1);
|
||||||
@ -2196,28 +2258,6 @@ tstrsequence(uchar c)
|
|||||||
term.esc |= ESC_STR;
|
term.esc |= ESC_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
tupdatebgcolor(int oldbg, int newbg)
|
|
||||||
{
|
|
||||||
for (int y = 0; y < term.row; y++) {
|
|
||||||
for (int x = 0; x < term.col; x++) {
|
|
||||||
if (term.line[y][x].bg == oldbg)
|
|
||||||
term.line[y][x].bg = newbg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
tupdatefgcolor(int oldfg, int newfg)
|
|
||||||
{
|
|
||||||
for (int y = 0; y < term.row; y++) {
|
|
||||||
for (int x = 0; x < term.col; x++) {
|
|
||||||
if (term.line[y][x].fg == oldfg)
|
|
||||||
term.line[y][x].fg = newfg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
tcontrolcode(uchar ascii)
|
tcontrolcode(uchar ascii)
|
||||||
{
|
{
|
||||||
@ -2352,7 +2392,7 @@ eschandle(uchar ascii)
|
|||||||
return 0;
|
return 0;
|
||||||
case 'D': /* IND -- Linefeed */
|
case 'D': /* IND -- Linefeed */
|
||||||
if (term.c.y == term.bot) {
|
if (term.c.y == term.bot) {
|
||||||
tscrollup(term.top, 1);
|
tscrollup(term.top, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
tmoveto(term.c.x, term.c.y+1);
|
tmoveto(term.c.x, term.c.y+1);
|
||||||
}
|
}
|
||||||
@ -2365,7 +2405,7 @@ eschandle(uchar ascii)
|
|||||||
break;
|
break;
|
||||||
case 'M': /* RI -- Reverse index */
|
case 'M': /* RI -- Reverse index */
|
||||||
if (term.c.y == term.top) {
|
if (term.c.y == term.top) {
|
||||||
tscrolldown(term.top, 1);
|
tscrolldown(term.top, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
tmoveto(term.c.x, term.c.y-1);
|
tmoveto(term.c.x, term.c.y-1);
|
||||||
}
|
}
|
||||||
@ -2579,7 +2619,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
|
|||||||
void
|
void
|
||||||
tresize(int col, int row)
|
tresize(int col, int row)
|
||||||
{
|
{
|
||||||
int i;
|
int i, j;
|
||||||
int minrow = MIN(row, term.row);
|
int minrow = MIN(row, term.row);
|
||||||
int mincol = MIN(col, term.col);
|
int mincol = MIN(col, term.col);
|
||||||
int *bp;
|
int *bp;
|
||||||
@ -2616,6 +2656,14 @@ tresize(int col, int row)
|
|||||||
term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
|
term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
|
||||||
term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
|
term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
|
||||||
|
|
||||||
|
for (i = 0; i < HISTSIZE; i++) {
|
||||||
|
term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
|
||||||
|
for (j = mincol; j < col; j++) {
|
||||||
|
term.hist[i][j] = term.c.attr;
|
||||||
|
term.hist[i][j].u = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* resize each row to new width, zero-pad if needed */
|
/* resize each row to new width, zero-pad if needed */
|
||||||
for (i = 0; i < minrow; i++) {
|
for (i = 0; i < minrow; i++) {
|
||||||
term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
|
term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
|
||||||
@ -2674,7 +2722,7 @@ drawregion(int x1, int y1, int x2, int y2)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
term.dirty[y] = 0;
|
term.dirty[y] = 0;
|
||||||
xdrawline(term.line[y], x1, y, x2);
|
xdrawline(TLINE(y), x1, y, x2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2695,6 +2743,7 @@ draw(void)
|
|||||||
cx--;
|
cx--;
|
||||||
|
|
||||||
drawregion(0, 0, term.col, term.row);
|
drawregion(0, 0, term.col, term.row);
|
||||||
|
if (term.scr == 0)
|
||||||
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
||||||
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
term.ocx = cx;
|
term.ocx = cx;
|
||||||
|
4
st.h
4
st.h
@ -81,6 +81,8 @@ void die(const char *, ...);
|
|||||||
void redraw(void);
|
void redraw(void);
|
||||||
void draw(void);
|
void draw(void);
|
||||||
|
|
||||||
|
void kscrolldown(const Arg *);
|
||||||
|
void kscrollup(const Arg *);
|
||||||
void printscreen(const Arg *);
|
void printscreen(const Arg *);
|
||||||
void printsel(const Arg *);
|
void printsel(const Arg *);
|
||||||
void sendbreak(const Arg *);
|
void sendbreak(const Arg *);
|
||||||
@ -90,8 +92,6 @@ int tattrset(int);
|
|||||||
void tnew(int, int);
|
void tnew(int, int);
|
||||||
void tresize(int, int);
|
void tresize(int, int);
|
||||||
void tsetdirtattr(int);
|
void tsetdirtattr(int);
|
||||||
void tupdatebgcolor(int, int);
|
|
||||||
void tupdatefgcolor(int, int);
|
|
||||||
void ttyhangup(void);
|
void ttyhangup(void);
|
||||||
int ttynew(const char *, char *, const char *, char **);
|
int ttynew(const char *, char *, const char *, char **);
|
||||||
size_t ttyread(void);
|
size_t ttyread(void);
|
||||||
|
52
x.c
52
x.c
@ -59,8 +59,6 @@ static void zoom(const Arg *);
|
|||||||
static void zoomabs(const Arg *);
|
static void zoomabs(const Arg *);
|
||||||
static void zoomreset(const Arg *);
|
static void zoomreset(const Arg *);
|
||||||
static void ttysend(const Arg *);
|
static void ttysend(const Arg *);
|
||||||
static void nextscheme(const Arg *);
|
|
||||||
static void selectscheme(const Arg *);
|
|
||||||
|
|
||||||
/* config.h for applying patches and the configuration. */
|
/* config.h for applying patches and the configuration. */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -187,7 +185,6 @@ static void mousesel(XEvent *, int);
|
|||||||
static void mousereport(XEvent *);
|
static void mousereport(XEvent *);
|
||||||
static char *kmap(KeySym, uint);
|
static char *kmap(KeySym, uint);
|
||||||
static int match(uint, uint);
|
static int match(uint, uint);
|
||||||
static void updatescheme(void);
|
|
||||||
|
|
||||||
static void run(void);
|
static void run(void);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
@ -788,7 +785,7 @@ xloadcols(void)
|
|||||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
||||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
||||||
} else {
|
} else {
|
||||||
dc.collen = 258;
|
dc.collen = MAX(LEN(colorname), 256);
|
||||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2011,47 +2008,6 @@ usage(void)
|
|||||||
" [stty_args ...]\n", argv0, argv0);
|
" [stty_args ...]\n", argv0, argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
nextscheme(const Arg *arg)
|
|
||||||
{
|
|
||||||
colorscheme += arg->i;
|
|
||||||
if (colorscheme >= (int)LEN(schemes))
|
|
||||||
colorscheme = 0;
|
|
||||||
else if (colorscheme < 0)
|
|
||||||
colorscheme = LEN(schemes) - 1;
|
|
||||||
updatescheme();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
selectscheme(const Arg *arg)
|
|
||||||
{
|
|
||||||
if (BETWEEN(arg->i, 0, LEN(schemes)-1)) {
|
|
||||||
colorscheme = arg->i;
|
|
||||||
updatescheme();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
updatescheme(void)
|
|
||||||
{
|
|
||||||
int oldbg, oldfg;
|
|
||||||
|
|
||||||
oldbg = defaultbg;
|
|
||||||
oldfg = defaultfg;
|
|
||||||
colorname = schemes[colorscheme].colors;
|
|
||||||
defaultbg = schemes[colorscheme].bg;
|
|
||||||
defaultfg = schemes[colorscheme].fg;
|
|
||||||
defaultcs = schemes[colorscheme].cs;
|
|
||||||
defaultrcs = schemes[colorscheme].rcs;
|
|
||||||
xloadcols();
|
|
||||||
if (defaultbg != oldbg)
|
|
||||||
tupdatebgcolor(oldbg, defaultbg);
|
|
||||||
if (defaultfg != oldfg)
|
|
||||||
tupdatefgcolor(oldfg, defaultfg);
|
|
||||||
cresize(win.w, win.h);
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -2104,12 +2060,6 @@ main(int argc, char *argv[])
|
|||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
run:
|
run:
|
||||||
colorname = schemes[colorscheme].colors;
|
|
||||||
defaultbg = schemes[colorscheme].bg;
|
|
||||||
defaultfg = schemes[colorscheme].fg;
|
|
||||||
defaultcs = schemes[colorscheme].cs;
|
|
||||||
defaultrcs = schemes[colorscheme].rcs;
|
|
||||||
|
|
||||||
if (argc > 0) /* eat all remaining arguments */
|
if (argc > 0) /* eat all remaining arguments */
|
||||||
opt_cmd = argv;
|
opt_cmd = argv;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user