extern int CLR_NormalText, CLR_GutterText, CLR_SelectedText, CLR_TagsBkg,
CLR_EditBkg, CLR_HorBorder, CLR_VerBorder, CLR_Ruler, CLR_ScrollBkg,
CLR_ThumbBkg, CLR_Cursor;
-extern int LineNumbers;
/* OS-Specific Config
******************************************************************************/
DblClickTime = 250, /* Millisecond time for detecting double clicks */
RulePosition = 80, /* Column in which the vertical ruler appears */
CopyIndent = 1, /* New lines will inherit the indent of the preceding line */
+ LineNumbers = 1, /* Enable line numbers by default or not */
};
#ifdef INCLUDE_DEFS
int CLR_Ruler = 1; // Ruler color
int CLR_Cursor = 7; // Cursor color
-int LineNumbers = 1;
-
#undef INCLUDE_DEFS
#endif
void win_dialog(char* name, void (*errfn)(char*));
void win_loop(void);
void win_settext(WinRegion id, char* text);
+void win_showlinenums(bool enable);
+bool win_getlinenums(void);
void win_setruler(size_t ruler);
Rune win_getkey(void);
void win_setkeys(KeyBinding* bindings);
static size_t fill_row(View* view, unsigned row, size_t pos, size_t* line) {
view_getrow(view, row)->off = pos;
- if (line)
+ if (line) {
+ if (pos > buf_end(&(view->buffer)))
+ *line = 0;
view_getrow(view, row)->line = *line;
+ }
clearrow(view, row);
for (size_t x = 0; x < view->ncols;) {
uint32_t attr = (in_selection(view->selection, pos) ? CLR_SelectedText : CLR_NormalText);
static Region Regions[NREGIONS] = {0};
static Rune LastKey;
static KeyBinding* Keys = NULL;
+static bool ShowLineNumbers = false;
static void win_init(void (*errfn)(char*)) {
for (int i = 0; i < SCROLL; i++)
buf_logclear(&(view->buffer));
}
+void win_setlinenums(bool enable) {
+ ShowLineNumbers = enable;
+}
+
+bool win_getlinenums(void) {
+ return ShowLineNumbers;
+}
+
void win_setruler(size_t ruler) {
Ruler = ruler;
}
}
static size_t gutter_cols(void) {
- size_t len = (LineNumbers ? 1 : 0),
+ size_t len = (ShowLineNumbers ? 1 : 0),
lines = win_buf(EDIT)->nlines;
- while (LineNumbers && lines > 9)
+ while (ShowLineNumbers && lines > 9)
lines /= 10, len++;
return len;
}
static size_t gutter_size(void) {
- return (gutter_cols() * x11_font_width(Font)) + (LineNumbers ? 5 : 0);
+ return (gutter_cols() * x11_font_width(Font)) + (ShowLineNumbers ? 5 : 0);
}
static void layout(int width, int height) {
size_t gsz = gutter_size();
if (Ruler)
x11_draw_rect(CLR_Ruler, ((Ruler+2) * fwidth) + gsz, Regions[i].y-2, 1, Regions[i].height+7);
- if (LineNumbers)
+ if (ShowLineNumbers)
x11_draw_rect(CLR_Ruler, Regions[SCROLL].width, Regions[SCROLL].y-2, gsz, Regions[SCROLL].height+7);
}
static void draw_line_num(size_t x, size_t y, size_t gcols, size_t num) {
UGlyph glyphs[gcols];
- if (LineNumbers) {
+ if (ShowLineNumbers) {
for (int i = gcols-1; i >= 0; i--) {
glyphs[i].attr = CLR_GutterText;
if (num > 0) {
}
static void tag_lnnum(void) {
- LineNumbers = !LineNumbers;
+ win_setlinenums(!win_getlinenums());
}
static void search(void) {
char* tags = getenv("EDITTAGS");
win_settext(TAGS, (tags ? tags : DefaultTags));
win_setruler(RulePosition);
+ win_setlinenums((bool)LineNumbers);
/* open the first file in this instance */
if (argc > 1)
edit_relative(argv[1]);