Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.4 #140

Merged
merged 96 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
c8c629c
Add command line option. -v and --version
fox0430 Nov 27, 2018
bb2e653
use parseopt
fox0430 Nov 27, 2018
7a4d13e
Refactor
fox0430 Nov 28, 2018
dbb7a18
Fix compile error
fox0430 Nov 28, 2018
2254ce9
Merge pull request #111 from fox0430/addCmdOp
fox0430 Nov 28, 2018
0e77d66
Add settings.nim
fox0430 Nov 29, 2018
625029f
Delete unnecessary file
fox0430 Nov 29, 2018
3043453
Merge pull request #113 from fox0430/settingfile
fox0430 Nov 30, 2018
e9a8016
Fix invalid settings file path and make parseSettingsFile more generic
walkre-niboshi Nov 30, 2018
c681fa0
fix wrong quit
walkre-niboshi Nov 30, 2018
ea57b8d
Merge pull request #115 from fox0430/improve-settings-file
fox0430 Nov 30, 2018
d97293f
Make settings file location XDG compliant
SolitudeSF Nov 30, 2018
9eb264f
Merge pull request #116 from SolitudeSF/xdg
fox0430 Nov 30, 2018
4207cec
Test implement of syntax highlight
fox0430 Dec 1, 2018
ad088b3
Fix column number in status bar
fox0430 Dec 1, 2018
e2654ea
Merge pull request #117 from fox0430/fixStatusBar
fox0430 Dec 1, 2018
b5d2439
Refactor
fox0430 Dec 2, 2018
ead2c57
Bugfix
fox0430 Dec 2, 2018
8f83481
Change timing of highlight update
fox0430 Dec 2, 2018
f372ea2
Bugfix and add color
fox0430 Dec 2, 2018
e7bd7c5
Refactor
fox0430 Dec 3, 2018
b5853b0
Bugfix
fox0430 Dec 3, 2018
dcca319
Add comment highlight
fox0430 Dec 3, 2018
a9cb3dc
Add supported language
fox0430 Dec 3, 2018
dbba673
Fix spelling
fox0430 Dec 3, 2018
fec1793
Add setting item and bugfix
fox0430 Dec 3, 2018
f448c41
Refactor
fox0430 Dec 3, 2018
726b630
Bugfix
fox0430 Dec 6, 2018
70fd9ed
Speedup syntax highlighting
walkre-niboshi Dec 9, 2018
686ab3a
Update editorstatus's test and more speedup
walkre-niboshi Dec 9, 2018
0f0d176
Insertmode: Bugfix #120
fox0430 Dec 13, 2018
0677985
Insertmode: Fix cursor position
fox0430 Dec 13, 2018
39a4268
Insertmode: Bug fix
fox0430 Dec 13, 2018
0d7536d
Merge pull request #121 from fox0430/fix#120
fox0430 Dec 13, 2018
93a95dd
add filerStatus object
fox0430 Dec 14, 2018
0b9aad9
Filer mode: Refactor and add file copy
fox0430 Dec 14, 2018
f720b0c
Filer mode: Refactor
fox0430 Dec 14, 2018
28f9d5d
Update develop version
fox0430 Dec 14, 2018
28245dc
Merge pull request #122 from fox0430/updateVer
fox0430 Dec 14, 2018
f681283
Update README.md
fox0430 Dec 14, 2018
4038d86
Merge pull request #123 from fox0430/updateReadme
fox0430 Dec 14, 2018
75bdced
Filer mode: Add cut file
fox0430 Dec 14, 2018
4cf8205
Filer mode: Error handling
fox0430 Dec 15, 2018
a4b7be2
Filer mode: Refactor
fox0430 Dec 15, 2018
2f11248
Improve initHighlight
walkre-niboshi Dec 15, 2018
e6e6c7c
Use stable Nim for .travis.yml
walkre-niboshi Dec 16, 2018
75723cc
Merge pull request #118 from fox0430/highlight
fox0430 Dec 16, 2018
a023721
update README.md
fox0430 Dec 16, 2018
83cacfb
Merge pull request #125 from fox0430/updateReadme
fox0430 Dec 16, 2018
6cd2468
update README.md
fox0430 Dec 16, 2018
e31fc7f
Filer mode: Add sort option
fox0430 Dec 16, 2018
cdf5712
Merge pull request #126 from fox0430/updateReadme
fox0430 Dec 16, 2018
6004028
Filer mode: Add sort by file size
fox0430 Dec 20, 2018
1beb1ad
Filer mode: Refactor and bugfix
fox0430 Dec 21, 2018
8d4b059
Filer mode: Bugfix #127
fox0430 Dec 22, 2018
59b660b
Filer mode: Add sort by last write time
fox0430 Dec 22, 2018
a65be28
Filer mode: Bugfix #127
fox0430 Dec 22, 2018
7ea2cff
Filer mode: Add create directory command
fox0430 Dec 22, 2018
1f79511
Merge pull request #124 from fox0430/improveFiler
fox0430 Dec 23, 2018
b50b5c5
Add line number setting
fox0430 Dec 23, 2018
b956678
Add line number setting
fox0430 Dec 24, 2018
976ae92
Add status bar setting
fox0430 Dec 24, 2018
d7323a9
Merge branch 'addSettingItems' of http://github.com/fox0430/moe into …
fox0430 Dec 24, 2018
92eb5f1
Filer mode: Bug fix #129
fox0430 Dec 28, 2018
de8228a
Merge pull request #130 from fox0430/fix#129
fox0430 Dec 28, 2018
d9f614b
Refactor
fox0430 Dec 29, 2018
3deb375
Add some status bar settings
fox0430 Dec 30, 2018
53068e0
Merge branch 'develop' into addSettingItems
fox0430 Jan 1, 2019
4710702
Merge pull request #128 from fox0430/addSettingItems
fox0430 Jan 1, 2019
2f06a7a
Add setIbeamCursor() and setBlockCursor()
fox0430 Jan 3, 2019
e7c1ec5
Add cursor setting
fox0430 Jan 3, 2019
3d93649
Bugfix
fox0430 Jan 5, 2019
55ce685
Change command to set block cusror
fox0430 Jan 5, 2019
e25170f
Ex mode: Buffix #133
fox0430 Jan 22, 2019
75d90b0
Ex mode: Fix compile error
fox0430 Jan 22, 2019
652ef66
Ex mode: Fix to enable syntax highlight
fox0430 Jan 22, 2019
6f5d7fe
Merge pull request #134 from fox0430/fix#133
fox0430 Jan 23, 2019
c55d48c
Ex mode: Bugfix #135
fox0430 Jan 24, 2019
4d2f0f8
Merge pull request #136 from fox0430/fix#135
fox0430 Jan 26, 2019
c4760b1
Merge pull request #132 from fox0430/cursorSetting
fox0430 Feb 15, 2019
57f9f05
Use my forked nim-ncurses repository instead of origin temporarily
walkre-niboshi Feb 22, 2019
d580324
Fix type conversions
walkre-niboshi Feb 22, 2019
1adb011
Merge pull request #139 from fox0430/fix-ncurses-installation-error
fox0430 Feb 27, 2019
8331638
Update moe.nimble
fox0430 Feb 28, 2019
aa17c95
Merge pull request #141 from fox0430/fixNimble
fox0430 Feb 28, 2019
15c3329
Add settings file example
fox0430 Feb 28, 2019
c4a16c4
Bugfix parse settings file
fox0430 Feb 28, 2019
087c6a1
Merge pull request #142 from fox0430/fixSettings
fox0430 Feb 28, 2019
552e4ad
Merge pull request #143 from fox0430/addFile
fox0430 Feb 28, 2019
0fe339d
Fix settings file example
fox0430 Feb 28, 2019
18729f8
Merge pull request #144 from fox0430/fixExample
fox0430 Feb 28, 2019
546e482
delete current line highlighting
fox0430 Mar 1, 2019
9ee5c60
Change image Color
fox0430 Mar 1, 2019
ddab77a
Merge pull request #145 from fox0430/currentLineColor
fox0430 Mar 1, 2019
64d82c2
Update README.md
fox0430 Mar 1, 2019
c85c17c
Merge pull request #146 from fox0430/updateReadme
fox0430 Mar 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ language: c
compiler:
- gcc
before_install:
# Set up libncursesw
- sudo ln -sf /lib/x86_64-linux-gnu/libncursesw.so.5.9 /usr/lib/x86_64-linux-gnu/libncursesw.so
# Install nim
- git clone https://github.com/nim-lang/nim
- cd nim
- git clone --depth 1 git://github.com/nim-lang/csources
- cd csources && sh build.sh
- cd ..
- bin/nim c koch
- ./koch boot -d:release
- ./koch nimble
- cd ..
- export CHOOSENIM_NO_ANALYTICS=1
- curl https://nim-lang.org/choosenim/init.sh -sSf > init.sh
- sh init.sh -y
- export PATH=~/.nimble/bin:$PATH
- echo "export PATH=~/.nimble/bin:$PATH" >> ~/.profile
- choosenim stable
before_script:
- set -e
- export PATH=$(pwd)/nim/bin:$(pwd):$PATH
script:
- nimble refresh
- yes | nimble test --verbose
- nimble install --verbose
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@

## moe

moe is a command line based text editor.
moe is a Vim inspired command line based text editor.

This project's goal is a funny animation editor.

![moe-0](https://user-images.githubusercontent.com/15966436/42743686-90deb5f8-88b5-11e8-9e5e-ae8202f64a98.jpg)
![moe-0](https://user-images.githubusercontent.com/15966436/53622086-03be0580-3c3c-11e9-8f28-469a6bc39602.png)

## Features
- Written in Nim

- Adopt GapBuffer

- UTF-8 and other encodings support (Incomplete)

- Vim like keybinds and mode

- Syntax highlighting (Nim, C, C++, C#, Java, Yaml)

- Simple file manager

- Auto close paren

- Simple auto indent

- UTF-8 and other encodings support (Incomplete)

## Planned features

- Syntax highlighting

- Visual mode

- Multi-Buffer

- Infinite undo/redo

- Syntax checker
Expand All @@ -44,6 +46,10 @@ This project's goal is a funny animation editor.

- Git support

- Select data structures

- Language Server Protocol

- Plugins

- Funny animation...
Expand Down
19 changes: 19 additions & 0 deletions example/moerc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Standard]
number = true
statusBar = true
syntax = true
tabStop = 2
autoCloseParen = true
autoIndent = true
defaultCursor = "block"
normalModeCursor = "block"
insertModeCursor = "ibeam"

[StatusBar]
mode = true
chanedMark = true
line = true
column = true
encoding = true
language = true
directory = true
9 changes: 5 additions & 4 deletions moe.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.35"
version = "0.0.4"
author = "fox0430/walkre"
description = "a command lined based text editor"
license = "GPLv3"
Expand All @@ -9,6 +9,7 @@ bin = @["moe"]

# Dependencies

requires "nim >= 0.18.0"
requires "ncurses >= 0.1.0"
requires "unicodedb >= 0.5.2"
requires "nim >= 0.19.4"
requires "https://github.com/walkre-niboshi/nim-ncurses >= 0.1.0"
requires "unicodedb >= 0.6.0"
requires "parsetoml >= 0.4.0"
34 changes: 23 additions & 11 deletions src/moe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@ import moepkg/editorview
import moepkg/gapbuffer
import moepkg/independentutils
import moepkg/unicodeext
import moepkg/cmdoption
import moepkg/settings
import moepkg/highlight

proc main() =
let parsedList = parseCommandLineOption(commandLineParams())

defer:
exitUi()

when isMainModule:
startUi()

var status = initEditorStatus()
if commandLineParams().len >= 1:
status.filename = commandLineParams()[0].toRunes
status.settings = parseSettingsFile(getConfigDir() / "moe" / "moerc.toml")

if parsedList.filename != "":
status.filename = parsedList.filename.toRunes
status.language = detectLanguage(parsedList.filename)
if existsFile($(status.filename)):
try:
let textAndEncoding = openFile(status.filename)
status.buffer = textAndEncoding.text.toGapBuffer
status.settings.characterEncoding = textAndEncoding.encoding
except IOError:
echo(fmt"Failed to open: {status.filename}")
exitUi()
quit()
writeFileOpenErrorMessage(status.commandWindow, status.filename)
return
elif existsDir($(status.filename)):
try:
setCurrentDir($(status.filename))
Expand All @@ -39,11 +49,11 @@ when isMainModule:
else:
status.buffer = newFile()

status.view = initEditorView(status.buffer, terminalHeight()-2, terminalWidth()-numberOfDigits(status.buffer.len)-2)

defer:
exitUi()
discard execShellCmd("printf '\\033[2 q'")
status.highlight = initHighlight($status.buffer, status.language)
let numberOfDigitsLen = if status.settings.lineNumber: numberOfDigits(status.buffer.len) - 2 else: 0
let useStatusBar = if status.settings.statusBar.useBar: 1 else: 0
status.view = initEditorView(status.buffer, terminalHeight() - useStatusBar - 1, terminalWidth() - numberOfDigitsLen)

while true:
case status.mode:
of Mode.normal:
Expand All @@ -57,5 +67,7 @@ when isMainModule:
of Mode.search:
searchMode(status)
of Mode.quit:
executeOnExit(status.settings)
break

when isMainModule: main()
21 changes: 21 additions & 0 deletions src/moepkg/cmdoption.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import parseopt, unicode

type
ComdParsedList* = tuple[
filename: string
]

proc parseCommandLineOption*(line: seq[string]): ComdParsedList =
result.filename = ""
var parsedLine = initOptParser(line)
for kind, key, val in parsedLine.getopt():
case kind:
of cmdArgument:
result.filename = key
of cmdShortOption, cmdLongOption:
case key:
of "v", "version":
echo "v0.0.4"
quit()
of cmdEnd:
assert(false)
96 changes: 70 additions & 26 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import terminal, os, strformat
import gapbuffer, editorview, ui, cursor, unicodeext
import packages/docutils/highlite, strutils, terminal, os, strformat
import gapbuffer, editorview, ui, cursor, unicodeext, highlight

type Mode* = enum
normal, insert, ex, filer, search, quit
Expand All @@ -8,14 +8,33 @@ type Registers* = object
yankedLines*: seq[seq[Rune]]
yankedStr*: seq[Rune]

type EditorSettings = object
type StatusBarSettings* = object
useBar*: bool
mode*: bool
filename*: bool
chanedMark*: bool
line*: bool
column*: bool
characterEncoding*: bool
language*: bool
directory*: bool

type EditorSettings* = object
statusBar*: StatusBarSettings
lineNumber*: bool
syntax*: bool
autoCloseParen*: bool
autoIndent*: bool
tabStop*: int
characterEncoding*: CharacterEncoding
characterEncoding*: CharacterEncoding # TODO: move to EditorStatus ...?
defaultCursor*: CursorType
normalModeCursor*: CursorType
insertModeCursor*: CursorType

type EditorStatus* = object
buffer*: GapBuffer[seq[Rune]]
highlight*: Highlight
language*: SourceLanguage
searchHistory*: seq[seq[Rune]]
view*: EditorView
cursor*: CursorPosition
Expand All @@ -40,59 +59,81 @@ proc initRegisters(): Registers =
result.yankedLines = @[]
result.yankedStr = @[]

proc initEditorSettings(): EditorSettings =
proc initStatusBarSettings*(): StatusBarSettings =
result.useBar = true
result.mode = true
result.filename = true
result.chanedMark = true
result.line = true
result.column = true
result.characterEncoding = true
result.language = true
result.directory = true

proc initEditorSettings*(): EditorSettings =
result.statusBar = initStatusBarSettings()
result.lineNumber = true
result.syntax = true
result.autoCloseParen = true
result.autoIndent = true
result.tabStop = 2
result.defaultCursor = CursorType.blockMode # Terminal default curosr shape
result.normalModeCursor = CursorType.blockMode
result.insertModeCursor = CursorType.ibeamMode

proc initEditorStatus*(): EditorStatus =
result.currentDir = getCurrentDir().toRunes
result.language = SourceLanguage.langNone
result.registers = initRegisters()
result.settings = initEditorSettings()
result.mode = Mode.normal
result.prevMode = Mode.normal

result.mainWindow = initWindow(terminalHeight()-2, terminalWidth(), 0, 0)
result.statusWindow = initWindow(1, terminalWidth(), terminalHeight()-2, 0, ui.ColorPair.blackGreen)
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.blackPink)
result.commandWindow = initWindow(1, terminalWidth(), terminalHeight()-1, 0)

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

if status.mode == Mode.filer:
status.statusWindow.write(0, 0, ru" FILER ", ui.ColorPair.blackWhite)
status.statusWindow.append(ru" ", ui.ColorPair.blackGreen)
status.statusWindow.append(getCurrentDir().toRunes, ui.ColorPair.blackGreen)
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.blackPink)
status.statusWindow.append(getCurrentDir().toRunes, ui.ColorPair.blackPink)
status.statusWindow.refresh
return

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)
status.statusWindow.append(if status.filename.len > 0: status.filename else: ru"No name", ui.ColorPair.blackGreen)
if status.countChange > 0: status.statusWindow.append(ru" [+]", ui.ColorPair.blackGreen)
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.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 = fmt"{status.currentLine+1}/{status.buffer.len}"
column = fmt"{status.currentColumn}/{status.buffer[status.currentLine].len}"
encoding = $status.settings.characterEncoding
info = fmt"{line} {column} {encoding} "
status.statusWindow.write(0, terminalWidth()-info.len, info, ui.Colorpair.blackGreen)
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.blackPink)
status.statusWindow.refresh

proc resize*(status: var EditorStatus, height, width: int) =
let
adjustedHeight = max(height, 4)
adjustedWidth = max(width, status.view.widthOfLineNum+4)

resize(status.mainWindow, adjustedHeight-2, adjustedWidth, 0, 0)
resize(status.statusWindow, 1, adjustedWidth, adjustedHeight-2, 0)
useStatusBar = if status.settings.statusBar.useBar: 1 else: 0

resize(status.mainWindow, adjustedHeight - useStatusBar - 1, adjustedWidth, 0, 0)
if status.settings.statusBar.useBar: resize(status.statusWindow, 1, adjustedWidth, adjustedHeight-2, 0)
resize(status.commandWindow, 1, adjustedWidth, adjustedHeight-1, 0)

if status.mode != Mode.filer:
status.view.resize(status.buffer, adjustedHeight-2, adjustedWidth-status.view.widthOfLineNum-1, status.view.widthOfLineNum)
status.view.resize(status.buffer, adjustedHeight - useStatusBar - 1, adjustedWidth-status.view.widthOfLineNum-1, status.view.widthOfLineNum)
status.view.seekCursor(status.buffer, status.currentLine, status.currentColumn)

writeStatusBar(status)
if status.settings.statusBar.useBar: writeStatusBar(status)

proc erase*(status: var EditorStatus) =
erase(status.mainWindow)
Expand All @@ -101,9 +142,9 @@ proc erase*(status: var EditorStatus) =

proc update*(status: var EditorStatus) =
setCursor(false)
writeStatusBar(status)
if status.settings.statusBar.useBar: writeStatusBar(status)
status.view.seekCursor(status.buffer, status.currentLine, status.currentColumn)
status.view.update(status.mainWindow, status.buffer, status.currentLine)
status.view.update(status.mainWindow, status.settings.lineNumber, status.buffer, status.highlight, status.currentLine)
status.cursor.update(status.view, status.currentLine, status.currentColumn)
status.mainWindow.write(status.cursor.y, status.view.widthOfLineNum+status.cursor.x, "")
status.mainWindow.refresh
Expand All @@ -112,3 +153,6 @@ proc update*(status: var EditorStatus) =
proc changeMode*(status: var EditorStatus, mode: Mode) =
status.prevMode = status.mode
status.mode = mode

proc executeOnExit*(settings: EditorSettings) =
changeCursorType(settings.defaultCursor)
Loading