Skip to content

Commit

Permalink
Preliminary user interface separation
Browse files Browse the repository at this point in the history
In theory only ui-curses.[hc] should depend on curses, however in
practice keyboard input is still handled in vis.c. Furthermore the
syntax definitions as well as keyboard bindings and selection code
in window.c still depends on some curses constants.

There is also a slight regression in that the window status bar
does not show the current mode name. This and related global state
should be eliminated in the future.
  • Loading branch information
martanne committed Apr 3, 2015
1 parent b3b1abc commit 9915b9f
Show file tree
Hide file tree
Showing 9 changed files with 839 additions and 637 deletions.
22 changes: 0 additions & 22 deletions config.def.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** start by reading from the top of vis.c up until config.h is included */
#define DEFAULT_TERM "xterm" /* default term to use if $TERM isn't set */
/* macros used to specify keys for key bindings */
#define ESC 0x1B
#define NONE(k) { .str = { k }, .code = 0 }
Expand Down Expand Up @@ -71,26 +70,6 @@ static Command cmds[] = {
{ /* array terminator */ },
};

/* draw a statubar, do whatever you want with win->statuswin curses window */
static void statusbar(EditorWin *win) {
bool focused = vis->win == win || vis->prompt->editor == win;
const char *filename = text_filename_get(win->text);
CursorPos pos = window_cursor_getpos(win->win);
wattrset(win->statuswin, focused ? A_REVERSE|A_BOLD : A_REVERSE);
mvwhline(win->statuswin, 0, 0, ' ', win->width);
mvwprintw(win->statuswin, 0, 0, "%s %s %s %s",
mode->name && mode->name[0] == '-' ? mode->name : "",
filename ? filename : "[No Name]",
text_modified(win->text) ? "[+]" : "",
vis->recording ? "recording": "");
char buf[win->width + 1];
int len = snprintf(buf, win->width, "%zd, %zd", pos.line, pos.col);
if (len > 0) {
buf[len] = '\0';
mvwaddstr(win->statuswin, 0, win->width - len - 1, buf);
}
}

/* called before any other keybindings are checked, if the function returns false
* the key is completely ignored. */
static bool vis_keypress(Key *key) {
Expand Down Expand Up @@ -796,7 +775,6 @@ static Config editors[] = {
{
.name = "vis",
.mode = &vis_modes[VIS_MODE_NORMAL],
.statusbar = statusbar,
.keypress = vis_keypress,
},
};
Expand Down
Loading

0 comments on commit 9915b9f

Please sign in to comment.