Skip to content

Commit

Permalink
Merge pull request #278 from jrfondren/add-theme-to-config
Browse files Browse the repository at this point in the history
add [Theme] as moerc.toml section
  • Loading branch information
fox0430 authored May 9, 2019
2 parents 441a952 + 1d91512 commit 918f05d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
31 changes: 1 addition & 30 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,7 @@ proc changeMode*(status: var EditorStatus, mode: Mode) =
status.bufStatus[status.currentBuffer].mode = mode

proc changeTheme*(status: var EditorStatus) =
if status.settings.editorColorTheme == ColorTheme.dark:
status.settings.editorColor.editor = Colorpair.brightWhiteDefauLt
status.settings.editorColor.lineNum = Colorpair.grayDefault
status.settings.editorColor.currentLineNum = Colorpair.cyanDefault
status.settings.editorColor.statusBar = Colorpair.brightWhiteBlue
status.settings.editorColor.statusBarMode = Colorpair.blackWhite
status.settings.editorColor.tab = Colorpair.brightWhiteDefault
status.settings.editorColor.currentTab = Colorpair.brightWhiteBlue
status.settings.editorColor.commandBar = Colorpair.brightWhiteDefault
status.settings.editorColor.errorMessage = Colorpair.redDefault
elif status.settings.editorColorTheme == ColorTheme.light:
status.settings.editorColor.editor = Colorpair.blackDefault
status.settings.editorColor.lineNum = Colorpair.grayDefault
status.settings.editorColor.currentLineNum = Colorpair.blackDefault
status.settings.editorColor.statusBar = Colorpair.cyanGray
status.settings.editorColor.statusBarMode = Colorpair.whiteCyan
status.settings.editorColor.tab = Colorpair.cyanGray
status.settings.editorColor.currentTab = Colorpair.whiteCyan
status.settings.editorColor.commandBar = Colorpair.blackDefault
status.settings.editorColor.errorMessage = Colorpair.redDefault
elif status.settings.editorColorTheme == ColorTheme.vivid:
status.settings.editorColor.editor = Colorpair.brightWhiteDefauLt
status.settings.editorColor.lineNum = Colorpair.grayDefault
status.settings.editorColor.currentLineNum = Colorpair.pinkDefault
status.settings.editorColor.statusBar = Colorpair.blackPink
status.settings.editorColor.statusBarMode = Colorpair.blackWhite
status.settings.editorColor.tab = Colorpair.brightWhiteDefault
status.settings.editorColor.currentTab = Colorpair.blackPink
status.settings.editorColor.commandBar = Colorpair.brightWhiteDefault
status.settings.editorColor.errorMessage = Colorpair.redDefault
status.settings.editorColor = ColorThemeTable[status.settings.editorColorTheme]

proc changeCurrentWin*(status:var EditorStatus, index: int) =
if index < status.mainWindowInfo.high and index > 0: status.currentMainWindow = index
Expand Down
1 change: 1 addition & 0 deletions src/moepkg/exmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ proc changeThemeSettingCommand(status: var EditorStatus, command: seq[Rune]) =
if command == ru"dark": status.settings.editorColorTheme = ColorTheme.dark
elif command == ru"light": status.settings.editorColorTheme = ColorTheme.light
elif command == ru"vivid": status.settings.editorColorTheme = ColorTheme.vivid
elif command == ru"config": status.settings.editorColorTheme = ColorTheme.config

changeTheme(status)
status.resize(terminalHeight(), terminalWidth())
Expand Down
39 changes: 39 additions & 0 deletions src/moepkg/settings.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import parsetoml
import editorstatus, ui
from strutils import parseEnum

proc getCursorType(cursorType, mode: string): CursorType =
case cursorType
Expand Down Expand Up @@ -83,3 +84,41 @@ proc parseSettingsFile*(filename: string): EditorSettings =

if settings["StatusBar"].contains("directory"):
result.statusBar.language = settings["StatusBar"]["directory"].getbool()

if settings.contains("Theme"):
if settings["Theme"].contains("baseTheme"):
let theme = parseEnum[ColorTheme](settings["Theme"]["baseTheme"].getStr())
ColorThemeTable[ColorTheme.config] = ColorThemeTable[theme]

template color(str: string): untyped =
parseEnum[ColorPair](settings["Theme"][str].getStr())

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

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

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

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

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

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

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

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

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

result.editorColorTheme = ColorTheme.config
result.editorColor = ColorThemeTable[ColorTheme.config]
48 changes: 48 additions & 0 deletions src/moepkg/ui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ColorPair* = enum
blueDefault = 20

type ColorTheme* = enum
config = 0
dark = 1
light = 2
vivid = 3
Expand All @@ -62,6 +63,53 @@ type EditorColor* = object
commandBar*: ColorPair
errorMessage*: ColorPair

var ColorThemeTable*: array[ColorTheme, EditorColor] = [
config: EditorColor(
editor: brightWhiteDefault,
lineNum: grayDefault,
currentLineNum: cyanDefault,
statusBar: brightWhiteBlue,
statusBarMode: blackWhite,
tab: brightWhiteDefault,
currentTab: brightWhiteBlue,
commandBar: brightWhiteDefault,
errorMessage: redDefault,
),
dark: EditorColor(
editor: brightWhiteDefault,
lineNum: grayDefault,
currentLineNum: cyanDefault,
statusBar: brightWhiteBlue,
statusBarMode: blackWhite,
tab: brightWhiteDefault,
currentTab: brightWhiteBlue,
commandBar: brightWhiteDefault,
errorMessage: redDefault,
),
light: EditorColor(
editor: blackDefault,
lineNum: grayDefault,
currentLineNum: blackDefault,
statusBar: cyanGray,
statusBarMode: whiteCyan,
tab: cyanGray,
currentTab: whiteCyan,
commandBar: blackDefault,
errorMessage: redDefault,
),
vivid: EditorColor(
editor: brightWhiteDefault,
lineNum: grayDefault,
currentLineNum: pinkDefault,
statusBar: blackPink,
statusBarMode: blackWhite,
tab: brightWhiteDefault,
currentTab: blackPink,
commandBar: brightWhiteDefault,
errorMessage: redDefault,
),
]

type Window* = object
cursesWindow*: ptr window
top, left, height*, width*: int
Expand Down

0 comments on commit 918f05d

Please sign in to comment.