Skip to content

Commit

Permalink
Merge pull request #325 from fox0430/v0.0.82
Browse files Browse the repository at this point in the history
v0.0.82
  • Loading branch information
fox0430 authored Jun 8, 2019
2 parents 4d820cc + 5a70a56 commit 4a4b21d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 41 deletions.
12 changes: 10 additions & 2 deletions example/moerc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ errorMessage = "red"

errorMessageBg = "default"

searchResult = "default"

searchResultBg = "red"

visualMode = "gray100"

visualModeBg = "purple_1"

defaultCharactorColor = "gray100"

gtKeywordColor = "seaGreen1_2"
Expand All @@ -88,9 +96,9 @@ gtStringLitColor = "purple_1"

gtDecNumberColor = "aqua"

gtCommentColor = "white"
gtCommentColor = "gray"

gtLongCommentColor = "white"
gtLongCommentColor = "gray"

gtWhitespaceColor = "gray100"

Expand Down
4 changes: 2 additions & 2 deletions moe.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.81"
version = "0.0.82"
author = "fox0430"
description = "A command lined based text editor"
license = "GPLv3"
Expand All @@ -10,6 +10,6 @@ bin = @["moe"]
# Dependencies

requires "nim >= 0.19.6"
requires "https://github.com/walkre-niboshi/nim-ncurses >= 0.1.0"
requires "https://github.com/walkre-niboshi/nim-ncurses >= 1.0.1"
requires "unicodedb >= 0.7.0"
requires "parsetoml >= 0.4.0"
13 changes: 11 additions & 2 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import gapbuffer, editorview, ui, cursor, unicodeext, highlight, independentutil
type Mode* = enum
normal, insert, visual, visualBlock, replace, ex, filer, search, bufManager

type SelectArea* = object
startLine*: int
startColumn*: int
endLine*: int
endColumn*: int

type Registers* = object
yankedLines*: seq[seq[Rune]]
yankedStr*: seq[Rune]
Expand Down Expand Up @@ -44,6 +50,7 @@ type BufferStatus* = object
view*: EditorView
language*: SourceLanguage
cursor*: CursorPosition
selectArea*: SelectArea
isHighlight*: bool
filename*: seq[Rune]
openDir: seq[Rune]
Expand Down Expand Up @@ -266,13 +273,15 @@ proc update*(status: var EditorStatus) =
let
bufIndex = status.mainWindowInfo[i].bufferIndex
isCurrentMainWin = if i == status.currentMainWindow: true else: false
color = EditorColorPair.defaultChar
isLineNumber = status.settings.lineNumber
isCurrentLineNumber = status.settings.currentLineNumber
isCursorLine = status.settings.cursorLine
isVisualMode = if status.bufStatus[bufIndex].mode == Mode.visual or status.bufStatus[bufIndex].mode == Mode.visualBlock: true else: false
startSelectedLine = status.bufStatus[bufIndex].selectArea.startLine
endSelectedLine = status.bufStatus[bufIndex].selectArea.endLine

status.bufStatus[bufIndex].view.seekCursor(status.bufStatus[bufIndex].buffer, status.bufStatus[bufIndex].currentLine, status.bufStatus[bufIndex].currentColumn)
status.bufStatus[bufIndex].view.update(status.mainWindowInfo[i].window, isLineNumber, isCurrentLineNumber, isCursorLine, isCurrentMainWin, status.bufStatus[bufIndex].buffer, status.bufStatus[bufIndex].highlight, color, status.bufStatus[bufIndex].currentLine)
status.bufStatus[bufIndex].view.update(status.mainWindowInfo[i].window, isLineNumber, isCurrentLineNumber, isCursorLine, isCurrentMainWin, isVisualMode, status.bufStatus[bufIndex].buffer, status.bufStatus[bufIndex].highlight, status.bufStatus[bufIndex].currentLine, startSelectedLine, endSelectedLine)

status.bufStatus[bufIndex].cursor.update(status.bufStatus[bufIndex].view, status.bufStatus[bufIndex].currentLine, status.bufStatus[bufIndex].currentColumn)

Expand Down
22 changes: 11 additions & 11 deletions src/moepkg/editorview.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ proc write(view: EditorView, win: var Window, y, x: int, str: seq[Rune], color:
const tab = " "
win.write(y, x, ($str).replace("\t", tab), color, false)

proc writeAllLines*[T](view: var EditorView, win: var Window, lineNumber, currentLineNumber, cursorLine, currentWin: bool, buffer: T, highlight: Highlight, editorColor: EditorColorPair, currentLine: int) =
proc writeAllLines*[T](view: var EditorView, win: var Window, lineNumber, currentLineNumber, cursorLine, currentWin, isVisualMode: bool, buffer: T, highlight: Highlight, currentLine, startSelectedLine, endSelectedLine: int) =
win.erase
view.widthOfLineNum = if lineNumber: buffer.len.numberOfDigits+1 else: 0
view.widthOfLineNum = if lineNumber: buffer.len.numberOfDigits + 1 else: 0

let
start = (view.originalLine[0], view.start[0])
Expand All @@ -193,7 +193,9 @@ proc writeAllLines*[T](view: var EditorView, win: var Window, lineNumber, curren

var x = view.widthOfLineNum
if view.length[y] == 0:
view.write(win, y, x, view.lines[y], EditorColorPair.defaultChar)
if isVisualMode and (y >= startSelectedLine and endSelectedLine >= y):
view.write(win, y, x, ru" ", EditorColorPair.visualMode)
else: view.write(win, y, x, view.lines[y], EditorColorPair.defaultChar)
continue

while i < highlight.len and highlight[i].firstRow < view.originalLine[y]: inc(i)
Expand All @@ -220,19 +222,17 @@ proc writeAllLines*[T](view: var EditorView, win: var Window, lineNumber, curren
win.attroff(Attributes.underline)
else: view.write(win, y, x, str, highlight[i].color)
x += width(str)
if last == highlight[i].lastColumn - view.start[y]:
# consumed a whole segment
inc(i)
if last == highlight[i].lastColumn - view.start[y]: inc(i) # consumed a whole segment
else: break

win.refresh

proc update*[T](view: var EditorView, win: var Window, lineNumber, currentLineNumber, cursorLine, currentWin: bool, buffer: T, highlight: Highlight, editorColor: EditorColorPair, currentLine: int) =
let widthOfLineNum = buffer.len.intToStr.len+1
if lineNumber and widthOfLineNum != view.widthOfLineNum: view.resize(buffer, view.height, view.width+view.widthOfLineNum-widthOfLineNum, widthOfLineNum)
view.writeAllLines(win, lineNumber, currentLineNumber, cursorLine, currentWin, buffer, highlight, editorColor, currentLine)
proc update*[T](view: var EditorView, win: var Window, lineNumber, currentLineNumber, cursorLine, currentWin, isVisualMode: bool, buffer: T, highlight: Highlight, currentLine, startSelectedLine, endSelectedLine: int) =
let widthOfLineNum = buffer.len.intToStr.len + 1
if lineNumber and widthOfLineNum != view.widthOfLineNum: view.resize(buffer, view.height, view.width + view.widthOfLineNum - widthOfLineNum, widthOfLineNum)
view.writeAllLines(win, lineNumber, currentLineNumber, cursorLine, currentWin, isVisualMode, buffer, highlight, currentLine, startSelectedLine, endSelectedLine)
view.updated = false

proc seekCursor*[T](view: var EditorView, buffer: T, currentLine, currentColumn: int) =
while currentLine < view.originalLine[0] or (currentLine == view.originalLine[0] and view.length[0] > 0 and currentColumn < view.start[0]): view.scrollUp(buffer)
while (view.originalLine[view.height-1] != -1 and currentLine > view.originalLine[view.height-1]) or (currentLine == view.originalLine[view.height-1] and view.length[view.height-1] > 0 and currentColumn >= view.start[view.height-1]+view.length[view.height-1]): view.scrollDown(buffer)
while (view.originalLine[view.height - 1] != -1 and currentLine > view.originalLine[view.height - 1]) or (currentLine == view.originalLine[view.height - 1] and view.length[view.height - 1] > 0 and currentColumn >= view.start[view.height - 1]+view.length[view.height - 1]): view.scrollDown(buffer)
12 changes: 12 additions & 0 deletions src/moepkg/settings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ proc parseSettingsFile*(filename: string): EditorSettings =
if settings["Theme"].contains("errorMessageBg"):
ColorThemeTable[ColorTheme.config].errorMessageBg = color("errorMessageBg")

if settings["Theme"].contains("searchResult"):
ColorThemeTable[ColorTheme.config].searchResult = color("searchResult")

if settings["Theme"].contains("searchResultBg"):
ColorThemeTable[ColorTheme.config].searchResultBg = color("searchResultBg")

if settings["Theme"].contains("visualMode"):
ColorThemeTable[ColorTheme.config].visualMode = color("visualMode")

if settings["Theme"].contains("visualModeBg"):
ColorThemeTable[ColorTheme.config].visualModeBg = color("visualModeBg")

if settings["Theme"].contains("defaultCharactorColor"):
ColorThemeTable[ColorTheme.config].defaultChar = color("defaultCharactorColor")

Expand Down
20 changes: 10 additions & 10 deletions src/moepkg/ui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ type EditorColor* = object
errorMessageBg*: Color
searchResult*: Color
searchResultBg*: Color
visualMode: Color
visualModeBg: Color
visualMode*: Color
visualModeBg*: Color
# color scheme
defaultChar*: Color
gtKeyword*: Color
Expand Down Expand Up @@ -382,8 +382,8 @@ var ColorThemeTable*: array[ColorTheme, EditorColor] = [
gtKeyword: seaGreen1_2,
gtStringLit: purple_1,
gtDecNumber: aqua,
gtComment: white,
gtLongComment: white,
gtComment: gray,
gtLongComment: gray,
gtWhitespace: gray100,
# filer mode
currentFile: gray100,
Expand Down Expand Up @@ -422,8 +422,8 @@ var ColorThemeTable*: array[ColorTheme, EditorColor] = [
gtKeyword: seaGreen1_2,
gtStringLit: purple_1,
gtDecNumber: aqua,
gtComment: white,
gtLongComment: white,
gtComment: gray,
gtLongComment: gray,
gtWhitespace: gray100,
# filer mode
currentFile: gray100,
Expand Down Expand Up @@ -462,8 +462,8 @@ var ColorThemeTable*: array[ColorTheme, EditorColor] = [
gtKeyword: seaGreen1_2,
gtStringLit: purple_1,
gtDecNumber: aqua,
gtComment: white,
gtLongComment: white,
gtComment: gray,
gtLongComment: gray,
gtWhitespace: gray100,
# filer mode
currentFile: black,
Expand Down Expand Up @@ -502,8 +502,8 @@ var ColorThemeTable*: array[ColorTheme, EditorColor] = [
gtKeyword: seaGreen1_2,
gtStringLit: purple_1,
gtDecNumber: aqua,
gtComment: white,
gtLongComment: white,
gtComment: gray,
gtLongComment: gray,
gtWhitespace: gray100,
# filer mode
currentFile: gray100,
Expand Down
23 changes: 9 additions & 14 deletions src/moepkg/visualmode.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import terminal, strutils, sequtils
import editorstatus, editorview, ui, gapbuffer, normalmode, highlight, unicodeext

type SelectArea = object
startLine: int
startColumn: int
endLine: int
endColumn: int

proc initColorSegment(startLine, startColumn: int): ColorSegment =
result.firstRow = startLine
result.firstColumn = startColumn
Expand Down Expand Up @@ -187,18 +181,19 @@ proc visualBlockCommand(status: var EditorStatus, area: var SelectArea, key: Run

proc visualMode*(status: var EditorStatus) =
status.resize(terminalHeight(), terminalWidth())
let currentBuf = status.currentBuffer

var colorSegment = initColorSegment(status.bufStatus[status.currentBuffer].currentLine, status.bufStatus[status.currentBuffer].currentColumn)
var area = initSelectArea(status.bufStatus[status.currentBuffer].currentLine, status.bufStatus[status.currentBuffer].currentColumn)
status.bufStatus[currentBuf].selectArea = initSelectArea(status.bufStatus[status.currentBuffer].currentLine, status.bufStatus[status.currentBuffer].currentColumn)

while status.bufStatus[status.currentBuffer].mode == Mode.visual or status.bufStatus[status.currentBuffer].mode == Mode.visualBlock:
let isBlockMode = if status.bufStatus[status.currentBuffer].mode == Mode.visualBlock: true else: false

area.updateSelectArea(status.bufStatus[status.currentBuffer].currentLine, status.bufStatus[status.currentBuffer].currentColumn)
colorSegment.updateColorSegment(area)
status.bufStatus[currentBuf].selectArea.updateSelectArea(status.bufStatus[status.currentBuffer].currentLine, status.bufStatus[status.currentBuffer].currentColumn)
colorSegment.updateColorSegment(status.bufStatus[currentBuf].selectArea)

status.updatehighlight
if isBlockMode: status.bufStatus[status.currentBuffer].highlight.overwriteColorSegmentBlock(area, status.bufStatus[status.currentBuffer].buffer)
if isBlockMode: status.bufStatus[status.currentBuffer].highlight.overwriteColorSegmentBlock(status.bufStatus[currentBuf].selectArea, status.bufStatus[status.currentBuffer].buffer)
else: status.bufStatus[status.currentBuffer].highlight = status.bufStatus[status.currentBuffer].highlight.overwrite(colorSegment)

status.update
Expand Down Expand Up @@ -236,15 +231,15 @@ proc visualMode*(status: var EditorStatus) =
elif key == ord('g'):
if getKey(status.mainWindowInfo[status.currentMainWindow].window) == ord('g'): moveToFirstLine(status)
elif key == ord('i'):
status.bufStatus[status.currentBuffer].currentLine = area.startLine
status.bufStatus[status.currentBuffer].currentLine = status.bufStatus[currentBuf].selectArea.startLine
status.changeMode(Mode.insert)
elif key == ord('I'):
status.bufStatus[status.currentBuffer].currentLine = area.startLine
status.bufStatus[status.currentBuffer].currentLine = status.bufStatus[currentBuf].selectArea.startLine
status.bufStatus[status.currentBuffer].currentColumn = 0
status.changeMode(Mode.insert)

else:
if isBlockMode: visualBlockCommand(status, area, key)
else: visualCommand(status, area, key)
if isBlockMode: visualBlockCommand(status, status.bufStatus[currentBuf].selectArea, key)
else: visualCommand(status, status.bufStatus[currentBuf].selectArea, key)
status.updatehighlight
status.changeMode(Mode.normal)

0 comments on commit 4a4b21d

Please sign in to comment.