-- text editor, particularly text drawing, horizontal wrap, vertical scrolling Text = {} -- draw a line starting from startpos to screen at y between State.left and State.right -- return y for the next line, and position of start of final screen line drawn function Text.draw(State, line_index, y, startpos) --? print('text.draw', line_index, y) local line = State.lines[line_index] local line_cache = State.line_cache[line_index] line_cache.starty = y line_cache.startpos = startpos -- wrap long lines local final_screen_line_starting_pos = startpos -- track value to return Text.populate_screen_line_starting_pos(State, line_index) assert(#line_cache.screen_line_starting_pos >= 1) for i=1,#line_cache.screen_line_starting_pos do local pos = line_cache.screen_line_starting_pos[i] if pos < startpos then -- render nothing else final_screen_line_starting_pos = pos local screen_line = Text.screen_line(line, line_cache, i) --? print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y) local frag_len = utf8.len(screen_line) -- render any highlights if State.selection1.line then local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len) Text.draw_highlight(State, line, State.left,y, pos, lo,hi) end if line_index == State.cursor1.line then -- render search highlight or cursor if State.search_term then local data = State.lines[State.cursor1.line].data local cursor_offset = Text.offset(data, State.cursor1.pos) if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then local save_selection = State.selection1 State.selection1 = {line=line_index, pos=State.cursor1.pos+utf8.len(State.search_term)} local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len) Text.draw_highlight(State, line, State.left,y, pos, lo,hi) State.selection1 = save_selection end else if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y) elseif pos + frag_len == State.cursor1.pos then -- Show cursor at end of line. -- This place also catches end of wrapping screen lines. That doesn't seem worth distinguishing. -- It seems useful to see a cursor whether your eye is on the left or right margin. Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y) end end end -- render fragment App.color(Text_color) App.screen.print(screen_line, State.left,y) y = y + State.line_height if y >= App.screen.height then break end end end return y, final_screen_line_starting_pos end function Text.screen_line(line, line_cache, i) local pos = line_cache.screen_line_starting_pos[i] local offset = Text.offset(line.data, pos) if i >= #line_cache.screen_line_starting_pos then return line.data:sub(offset) end local endpos = line_cache.screen_line_starting_pos[i+1]-1 local end_offset = Text.offset(line.data, endpos) return line.data:sub(offset, end_offset) end function Text.draw_cursor(State, x, y) -- blink every 0.5s if math.floor(Cursor_time*2)%2 == 0 then App.color(Cursor_color) love.graphics.rectangle('fill', x,y, 3,State.line_height) end State.cursor_x = x State.cursor_y = y+State.line_height end function Text.populate_screen_line_starting_pos(State, line_index) local line = State.lines[line_index] if line.mode ~= 'text' then return end local line_cache = State.line_cache[line_index] if line_cac
# dwm version
VERSION = 1.6
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
# compiler and linker
CC = cc
LD = ${CC}