Skip to content

Commit

Permalink
Merge pull request #145 from fox0430/currentLineColor
Browse files Browse the repository at this point in the history
Change image color
  • Loading branch information
fox0430 authored Mar 1, 2019
2 parents 18729f8 + 9ee5c60 commit ddab77a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ proc initEditorStatus*(): EditorStatus =
let useStatusBar = if result.settings.statusBar.useBar: 1 else: 0
result.mainWindow = initWindow(terminalHeight()-1, terminalWidth(), 0, 0)
if result.settings.statusBar.useBar:
result.statusWindow = initWindow(1, terminalWidth(), terminalHeight() - useStatusBar - 1, 0, ui.ColorPair.blackGreen)
result.statusWindow = initWindow(1, terminalWidth(), terminalHeight() - useStatusBar - 1, 0, ui.ColorPair.blackPink)
result.commandWindow = initWindow(1, terminalWidth(), terminalHeight()-1, 0)

proc writeStatusBar*(status: var EditorStatus) =
status.statusWindow.erase

if status.mode == Mode.filer:
if status.settings.statusBar.mode: status.statusWindow.write(0, 0, ru" FILER ", ui.ColorPair.blackWhite)
if status.settings.statusBar.directory: status.statusWindow.append(ru" ", ui.ColorPair.blackGreen)
status.statusWindow.append(getCurrentDir().toRunes, ui.ColorPair.blackGreen)
if status.settings.statusBar.directory: status.statusWindow.append(ru" ", ui.ColorPair.blackPink)
status.statusWindow.append(getCurrentDir().toRunes, ui.ColorPair.blackPink)
status.statusWindow.refresh
return

if status.settings.statusBar.mode: status.statusWindow.write(0, 0, if status.mode == Mode.normal: ru" NORMAL " else: ru" INSERT ", ui.ColorPair.blackWhite)
status.statusWindow.append(ru" ", ui.ColorPair.blackGreen)
if status.settings.statusBar.filename: status.statusWindow.append(if status.filename.len > 0: status.filename else: ru"No name", ui.ColorPair.blackGreen)
if status.countChange > 0 and status.settings.statusBar.chanedMark: status.statusWindow.append(ru" [+]", ui.ColorPair.blackGreen)
status.statusWindow.append(ru" ", ui.ColorPair.blackPink)
if status.settings.statusBar.filename: status.statusWindow.append(if status.filename.len > 0: status.filename else: ru"No name", ui.ColorPair.blackPink)
if status.countChange > 0 and status.settings.statusBar.chanedMark: status.statusWindow.append(ru" [+]", ui.ColorPair.blackPink)

let
line = if status.settings.statusBar.line: fmt"{status.currentLine+1}/{status.buffer.len}" else: ""
column = if status.settings.statusBar.column: fmt"{status.currentColumn + 1}/{status.buffer[status.currentLine].len}" else: ""
encoding = if status.settings.statusBar.characterEncoding: $status.settings.characterEncoding else: ""
language = if status.language == SourceLanguage.langNone: "Plain" else: sourceLanguageToStr[status.language]
info = fmt"{line} {column} {encoding} {language} "
status.statusWindow.write(0, terminalWidth()-info.len, info, ui.Colorpair.blackGreen)
status.statusWindow.write(0, terminalWidth()-info.len, info, ui.Colorpair.blackPink)
status.statusWindow.refresh

proc resize*(status: var EditorStatus, height, width: int) =
Expand Down
4 changes: 2 additions & 2 deletions src/moepkg/editorview.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ proc writeAllLines*(view: var EditorView, win: var Window, lineNumber: bool, buf

let isCurrentLine = view.originalLine[y] == currentLine
if lineNumber and view.start[y] == 0:
view.writeLineNum(win, y, view.originalLine[y], if isCurrentLine: ColorPair.brightGreenDefault else: ColorPair.grayDefault)
view.writeLineNum(win, y, view.originalLine[y], if isCurrentLine: ColorPair.pinkDefault else: ColorPair.grayDefault)

var x = view.widthOfLineNum
if view.length[y] == 0:
Expand All @@ -203,7 +203,7 @@ proc writeAllLines*(view: var EditorView, win: var Window, lineNumber: bool, buf
last = min(highlight[i].lastColumn-view.start[y], view.lines[y].high)
assert(0 <= first and last <= view.lines[y].high and first <= last, fmt"first = {first}, last = {last}, firstColumn = {highlight[i].firstColumn}, lastColumn = {highlight[i].lastColumn}, view.start[y] = {view.start[y]}, y = {y}, view.lines[y] = {view.lines[y]}, view.originalLine[y] = {view.originalLine[y]}")
let str = view.lines[y][first .. last]
view.write(win, y, x, str, if isCurrentLine: ColorPair.brightGreenDefault else: highlight[i].color)
view.write(win, y, x, str, highlight[i].color)
x += width(str)
if last == highlight[i].lastColumn - view.start[y]:
# consumed a whole segment
Expand Down
7 changes: 6 additions & 1 deletion src/moepkg/ui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type Color* = enum
magenta = 5,
cyan = 6,
white = 7,
lightBlue = 14
lightBlue = 14,
brightGreen = 85,
pink = 198,
brightWhite = 231,
gray = 245,

Expand All @@ -37,6 +38,8 @@ type ColorPair* = enum
whiteCyan = 11
magentaDefault =12
whiteDefault = 13
pinkDefault = 14
blackPink = 15

type Window* = object
cursesWindow*: ptr window
Expand All @@ -63,6 +66,8 @@ proc setCursesColor() =
setColorPair(ColorPair.whiteCyan, Color.white, Color.cyan)
setColorPair(ColorPair.magentaDefault, Color.magenta, Color.default)
setColorPair(ColorPair.whiteDefault, Color.white, Color.default)
setColorPair(ColorPair.pinkDefault, Color.pink, Color.default)
setColorPair(ColorPair.blackPink, Color.black, Color.pink)

proc setIbeamCursor*() =
discard execShellCmd("printf '\\033[6 q'")
Expand Down

0 comments on commit ddab77a

Please sign in to comment.