Add multi language support, match file ext with language, log file

This commit is contained in:
Adrian Wozniak 2019-01-04 21:42:39 +01:00
parent 3a5587dbcc
commit 3a39fab87a
No known key found for this signature in database
GPG Key ID: 3B441F7808FC43C7
22 changed files with 604 additions and 231 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target /target
**/*.rs.bk **/*.rs.bk
.idea .idea
log

241
Cargo.lock generated
View File

@ -1,3 +1,11 @@
[[package]]
name = "aho-corasick"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "argon2rs" name = "argon2rs"
version = "0.2.5" version = "0.2.5"
@ -15,6 +23,16 @@ dependencies = [
"nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "atty"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "0.1.1" version = "0.1.1"
@ -74,6 +92,11 @@ dependencies = [
"constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "byteorder"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "c_vec" name = "c_vec"
version = "1.3.2" version = "1.3.2"
@ -89,6 +112,16 @@ name = "cfg-if"
version = "0.1.6" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cloudabi" name = "cloudabi"
version = "0.0.3" version = "0.0.3"
@ -113,16 +146,15 @@ dependencies = [
] ]
[[package]] [[package]]
name = "editor" name = "env_logger"
version = "0.1.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"plex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -159,6 +191,14 @@ name = "fuchsia-zircon-sys"
version = "0.3.3" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "humantime"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.3" version = "0.4.3"
@ -174,11 +214,34 @@ name = "lazy_static"
version = "0.2.11" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.45" version = "0.2.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "nodrop" name = "nodrop"
version = "0.1.13" version = "0.1.13"
@ -236,6 +299,11 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "quick-error"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "quote" name = "quote"
version = "0.6.10" version = "0.6.10"
@ -303,6 +371,14 @@ name = "redox_syscall"
version = "0.1.50" version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "redox_users" name = "redox_users"
version = "0.2.0" version = "0.2.0"
@ -314,6 +390,42 @@ dependencies = [
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "regex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rider"
version = "0.1.0"
dependencies = [
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"plex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
"simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.13" version = "0.1.13"
@ -376,6 +488,16 @@ dependencies = [
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "simplelog"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "0.14.9" version = "0.14.9"
@ -407,16 +529,76 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "term"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucd-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "utf8-ranges"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.6.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.6" version = "0.3.6"
@ -431,14 +613,33 @@ name = "winapi-i686-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-util"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wincolor"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata] [metadata]
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" "checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727" "checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727"
"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" "checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5"
"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
@ -447,20 +648,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
"checksum c_vec 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6c32b15e95ce816aaf991a41420854e6ba772a2679a9296d906eab1114f1b4e9" "checksum c_vec 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6c32b15e95ce816aaf991a41420854e6ba772a2679a9296d906eab1114f1b4e9"
"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" "checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a" "checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum lalr 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "106d7548f95adbe3019b4fc4954554d7b72535867aa9ce326d2f766b68958de7" "checksum lalr 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "106d7548f95adbe3019b4fc4954554d7b72535867aa9ce326d2f766b68958de7"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" "checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db4c41318937f6e76648f42826b1d9ade5c09cafb5aef7e351240a70f39206e9"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
@ -468,6 +676,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum plex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "59d79bd74b3d0be2619e58217e8b2b96372e3feca8426e5c560623205d70c146" "checksum plex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "59d79bd74b3d0be2619e58217e8b2b96372e3feca8426e5c560623205d70c146"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" "checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
@ -476,7 +685,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" "checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db"
"checksum redfa 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "29cc2771cc9f5fb0061cdedc05a37170254694dffec6b89920a6e767f08c4220" "checksum redfa 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "29cc2771cc9f5fb0061cdedc05a37170254694dffec6b89920a6e767f08c4220"
"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" "checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26" "checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26"
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f"
"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
@ -485,11 +697,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "0e732ed5a5592c17d961555e3b552985baf98d50ce418b7b655f31f6ba7eb1b7" "checksum serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "0e732ed5a5592c17d961555e3b552985baf98d50ce418b7b655f31f6ba7eb1b7"
"checksum serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d6115a3ca25c224e409185325afc16a0d5aaaabc15c42b09587d6f1ba39a5b" "checksum serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d6115a3ca25c224e409185325afc16a0d5aaaabc15c42b09587d6f1ba39a5b"
"checksum serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545" "checksum serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545"
"checksum simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e95345f185d5adeb8ec93459d2dc99654e294cc6ccf5b75414d8ea262de9a13"
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" "checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
"checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f" "checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"

View File

@ -1,5 +1,5 @@
[package] [package]
name = "editor" name = "rider"
version = "0.1.0" version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"] authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018" edition = "2018"
@ -11,6 +11,9 @@ dirs = "*"
serde = "*" serde = "*"
serde_json = "*" serde_json = "*"
serde_derive = "*" serde_derive = "*"
log = "*"
env_logger = "*"
simplelog = "*"
[dependencies.sdl2] [dependencies.sdl2]
version = "0.31.0" version = "0.31.0"

View File

@ -1,15 +1,17 @@
use crate::app::caret_manager;
use crate::app::file_content_manager;
use crate::app::{UpdateResult, WindowCanvas}; use crate::app::{UpdateResult, WindowCanvas};
use crate::config::Config; use crate::config::Config;
use crate::renderer::Renderer; use crate::renderer::Renderer;
use crate::ui::caret::Caret; use crate::ui::caret::Caret;
use crate::ui::caret::{CaretPosition, MoveDirection};
use crate::ui::file::editor_file::EditorFile; use crate::ui::file::editor_file::EditorFile;
use crate::ui::file::*; use crate::ui::file::*;
use crate::ui::menu_bar::MenuBar; use crate::ui::menu_bar::MenuBar;
use crate::ui::caret::{CaretPosition, MoveDirection};
use crate::ui::text_character::TextCharacter; use crate::ui::text_character::TextCharacter;
use crate::ui::*; use crate::ui::*;
use sdl2::rect::{Point, Rect}; use sdl2::rect::{Point, Rect};
use sdl2::VideoSubsystem; use sdl2::VideoSubsystem as VS;
use std::boxed::Box; use std::boxed::Box;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@ -35,152 +37,37 @@ impl AppState {
pub fn open_file(&mut self, file_path: String) { pub fn open_file(&mut self, file_path: String) {
use std::fs::read_to_string; use std::fs::read_to_string;
if let Ok(buffer) = read_to_string(&file_path) { if let Ok(buffer) = read_to_string(&file_path) {
let file = EditorFile::new(file_path.clone(), buffer, self.config.clone()); let file = EditorFile::new(file_path.clone(), buffer, self.config.clone());
self.current_file = self.files.len(); self.current_file = self.files.len();
self.files.push(file); self.files.push(file);
} else {
eprintln!("Failed to open file: {}", file_path);
}; };
} }
pub fn caret(&mut self) -> &mut Caret { pub fn config(&self) -> &Rc<Config> {
&self.config
}
pub fn caret(&self) -> &Caret {
&self.caret
}
pub fn caret_mut(&mut self) -> &mut Caret {
&mut self.caret &mut self.caret
} }
pub fn delete_front(&mut self) { pub fn current_file(&self) -> Option<&EditorFile> {
let file: &mut EditorFile = if let Some(file) = self.files.get_mut(self.current_file) {
file
} else {
return;
};
let mut buffer: String = file.buffer();
let caret: &mut Caret = &mut self.caret;
let position: CaretPosition = caret.position().clone();
if position.text_position() == 0 {
return;
}
let c: char = buffer.chars().collect::<Vec<char>>()[position.text_position() - 1];
buffer.remove(position.text_position() - 1);
let position = match c {
'\n' => CaretPosition::new(
position.text_position() - 1,
position.line_number() - 1,
0,
),
_ => CaretPosition::new(
position.text_position() - 1,
position.line_number(),
position.line_position(),
)
};
match file.get_character_at(position.text_position()) {
Some(character) => {
let dest: &Rect = character.dest();
caret.move_caret(position, Point::new(dest.x(), dest.y()));
}
_ => {
caret.reset_caret();
}
}
let new_file = EditorFile::new(file.path(), buffer, self.config.clone());
self.files[self.current_file] = new_file;
}
pub fn delete_back(&mut self) {
let file: &mut EditorFile = if let Some(file) = self.files.get_mut(self.current_file) {
file
} else {
return;
};
let mut buffer: String = file.buffer();
let caret: &mut Caret = &mut self.caret;
let position: usize = caret.text_position();
if position >= buffer.len() {
return;
}
buffer.remove(position);
let new_file = EditorFile::new(file.path(), buffer, self.config.clone());
self.files[self.current_file] = new_file;
}
pub fn insert_text(&mut self, text: String, renderer: &mut Renderer) {
let file: &mut EditorFile = if let Some(file) = self.files.get_mut(self.current_file) {
file
} else {
return;
};
let mut buffer: String = file.buffer();
let caret: &mut Caret = &mut self.caret;
let current = match file.get_character_at(caret.text_position()) {
Some(c) => c,
_ => return,
};
let mut pos = Point::new(current.dest().x(), current.dest().y());
let mut position: CaretPosition = caret.position().clone();
for character in text.chars() {
buffer.insert(position.text_position(), character);
if let Some(rect) = get_text_character_rect(character, renderer) {
pos = pos + Point::new(rect.width() as i32, 0);
position = CaretPosition::new(
position.text_position() + 1,
position.line_number(),
position.line_position(),
);
caret.move_caret(position, pos.clone());
}
}
let new_file = EditorFile::new(file.path(), buffer, self.config.clone());
self.files[self.current_file] = new_file;
}
pub fn insert_new_line(&mut self, renderer: &mut Renderer) {
let file: &mut EditorFile = if let Some(file) = self.files.get_mut(self.current_file) {
file
} else {
return;
};
let mut buffer: String = file.buffer();
let caret: &mut Caret = &mut self.caret;
let current = match file.get_character_at(caret.text_position()) {
Some(c) => c,
_ => return,
};
let mut pos = Point::new(current.dest().x(), current.dest().y());
let mut position: CaretPosition = caret.position().clone();
buffer.insert(position.text_position(), '\n');
if let Some(rect) = get_text_character_rect('\n', renderer) {
pos = Point::new(
self.config.editor_left_margin(),
pos.y() + rect.height() as i32,
);
position = CaretPosition::new(
position.text_position(),
position.line_number() + 1,
0,
);
caret.move_caret(position, pos.clone());
}
let new_file = EditorFile::new(file.path(), buffer, self.config.clone());
self.files[self.current_file] = new_file;
}
fn current_file(&self) -> Option<&EditorFile> {
self.files.get(self.current_file) self.files.get(self.current_file)
} }
fn current_file_mut(&mut self) -> Option<&mut EditorFile> { pub fn current_file_mut(&mut self) -> Option<&mut EditorFile> {
self.files.get_mut(self.current_file) self.files.get_mut(self.current_file)
} }
fn on_editor_clicked( fn on_editor_clicked(&mut self, point: &Point, video_subsystem: &mut VS) -> UpdateResult {
&mut self,
point: &Point,
video_subsystem: &mut VideoSubsystem,
) -> UpdateResult {
let current_file: &mut EditorFile = if let Some(current_file) = self.current_file_mut() { let current_file: &mut EditorFile = if let Some(current_file) = self.current_file_mut() {
current_file current_file
} else { } else {
@ -204,49 +91,30 @@ impl AppState {
pub fn move_caret(&mut self, dir: MoveDirection) { pub fn move_caret(&mut self, dir: MoveDirection) {
match dir { match dir {
MoveDirection::Left => {} MoveDirection::Left => {}
MoveDirection::Right => MoveDirection::Right => caret_manager::move_caret_right(self),
self.move_caret_right(),
MoveDirection::Up => {} MoveDirection::Up => {}
MoveDirection::Down => {} MoveDirection::Down => {}
} }
} }
fn move_caret_right(&mut self) { pub fn delete_front(&mut self) {
let file: &EditorFile = match self.current_file() { file_content_manager::delete_front(self);
None => return, }
Some(f) => f,
}; pub fn delete_back(&mut self) {
let line = self.caret.line_number().clone(); file_content_manager::delete_back(self);
let characters: Vec<&TextCharacter> = match file.get_line(&line) { }
None =>
return, pub fn insert_text(&mut self, text: String, renderer: &mut Renderer) {
Some(characters) => characters, file_content_manager::insert_text(self, text, renderer);
}; }
let mut idx = 0;
for (i, c) in characters.iter().enumerate() { pub fn insert_new_line(&mut self, renderer: &mut Renderer) {
if c.position() == self.caret.text_position() { file_content_manager::insert_new_line(self, renderer);
idx = i + 1; }
break;
} pub fn replace_current_file(&mut self, file: EditorFile) {
}; self.files[self.current_file] = file;
let text_character: &TextCharacter = match characters.get(idx) {
Some(text_character) => text_character,
None => return,
};
let line = text_character.line() - self.caret.line_number();
let pos = self.caret
.position()
.moved(1, line, 0);
let mut d: Rect = text_character.dest().clone();
if text_character.is_new_line() {
let prev = match characters.get(idx - 1) {
Some(c) => c,
_ => return,
};
d = prev.dest().clone();
d.set_x(d.x() + d.width() as i32);
}
self.caret.move_caret(pos, Point::new(d.x(), d.y()));
} }
} }
@ -273,11 +141,7 @@ impl Update for AppState {
} }
impl AppState { impl AppState {
pub fn on_left_click( pub fn on_left_click(&mut self, point: &Point, video_subsystem: &mut VS) -> UpdateResult {
&mut self,
point: &Point,
video_subsystem: &mut VideoSubsystem,
) -> UpdateResult {
if self.menu_bar.is_left_click_target(point) { if self.menu_bar.is_left_click_target(point) {
video_subsystem.text_input().stop(); video_subsystem.text_input().stop();
return self.menu_bar.on_left_click(point); return self.menu_bar.on_left_click(point);

54
src/app/caret_manager.rs Normal file
View File

@ -0,0 +1,54 @@
use crate::app::AppState;
use crate::ui::file::editor_file::EditorFile;
use crate::ui::text_character::TextCharacter;
use sdl2::rect::{Point, Rect};
pub fn move_caret_right(app_state: &mut AppState) {
let file: &EditorFile = match app_state.current_file() {
None => return,
Some(f) => f,
};
let line = match file.get_character_at(app_state.caret().text_position()) {
Some(t) if t.is_new_line() => app_state.caret().line_number().clone() + 1,
Some(_) => app_state.caret().line_number().clone(),
None => 0,
};
let characters: Vec<&TextCharacter> = match file.get_line(&line) {
None => return,
Some(characters) => characters,
};
let mut idx = 0;
for (i, c) in characters.iter().enumerate() {
if c.position() == app_state.caret().text_position() {
idx = i + 1;
break;
}
}
let text_character: &TextCharacter = match characters.get(idx) {
Some(text_character) => text_character,
None => return,
};
let line = line - app_state.caret().line_number();
let pos = app_state.caret().position().moved(1, line as i32, 0);
let mut d: Rect = text_character.dest().clone();
if text_character.is_new_line() && idx > 0 {
let prev = match characters.get(idx - 1) {
Some(c) => c,
_ => return,
};
d = prev.dest().clone();
d.set_x(d.x() + d.width() as i32);
}
app_state
.caret_mut()
.move_caret(pos, Point::new(d.x(), d.y()));
}
pub fn move_caret_left(app_state: &mut AppState) {
let _file: &EditorFile = match app_state.current_file() {
None => return,
Some(f) => f,
};
let _line = app_state.caret().line_number();
}

View File

@ -0,0 +1,143 @@
use crate::app::AppState;
use crate::renderer::Renderer;
use crate::ui::caret::Caret;
use crate::ui::caret::CaretPosition;
use crate::ui::file::editor_file::EditorFile;
use crate::ui::get_text_character_rect;
use crate::ui::text_character::TextCharacter;
use sdl2::rect::Point;
use sdl2::rect::Rect;
fn get_character_at(app_state: &mut AppState, index: usize) -> Option<&TextCharacter> {
match app_state.current_file() {
None => return None,
Some(f) => f,
}
.get_character_at(index)
}
fn current_file_path(app_state: &mut AppState) -> String {
match app_state.current_file() {
Some(f) => f.path(),
_ => String::new(),
}
}
pub fn delete_front(app_state: &mut AppState) {
let mut buffer: String = if let Some(file) = app_state.current_file() {
file
} else {
return;
}
.buffer();
let position: CaretPosition = app_state.caret().position().clone();
if position.text_position() == 0 {
return;
}
let c: char = buffer.chars().collect::<Vec<char>>()[position.text_position() - 1];
buffer.remove(position.text_position() - 1);
let position = match c {
'\n' if position.text_position() > 0 && position.line_number() > 0 => {
position.moved(-1, -1, 0)
}
'\n' => position.clone(),
_ if position.text_position() > 0 => position.moved(-1, 0, 0),
_ => position.moved(0, 0, 0),
};
let move_to = match get_character_at(app_state, position.text_position()) {
Some(character) => {
let dest: &Rect = character.dest();
Some((position, Point::new(dest.x(), dest.y())))
}
_ => None,
};
match move_to {
Some((position, point)) => app_state.caret_mut().move_caret(position, point),
None => app_state.caret_mut().reset_caret(),
};
let new_file = EditorFile::new(
current_file_path(app_state),
buffer,
app_state.config().clone(),
);
app_state.replace_current_file(new_file);
}
pub fn delete_back(app_state: &mut AppState) {
let file: &EditorFile = if let Some(file) = app_state.current_file() {
file
} else {
return;
};
let mut buffer: String = file.buffer();
let position: usize = app_state.caret().text_position();
if position >= buffer.len() {
return;
}
buffer.remove(position);
let new_file = EditorFile::new(file.path(), buffer, app_state.config().clone());
app_state.replace_current_file(new_file);
}
pub fn insert_text(app_state: &mut AppState, text: String, renderer: &mut Renderer) {
let mut buffer: String = if let Some(file) = app_state.current_file() {
file
} else {
return;
}
.buffer();
let current = match get_character_at(app_state, app_state.caret().text_position()) {
Some(c) => c,
_ => return,
};
let mut pos = Point::new(current.dest().x(), current.dest().y());
let mut position: CaretPosition = app_state.caret().position().clone();
for character in text.chars() {
buffer.insert(position.text_position(), character);
if let Some(rect) = get_text_character_rect(character, renderer) {
pos = pos + Point::new(rect.width() as i32, 0);
position = position.moved(1, 0, 0);
app_state.caret_mut().move_caret(position, pos.clone());
}
}
let new_file = EditorFile::new(
current_file_path(app_state),
buffer,
app_state.config().clone(),
);
app_state.replace_current_file(new_file);
}
pub fn insert_new_line(app_state: &mut AppState, renderer: &mut Renderer) {
let mut buffer: String = if let Some(file) = app_state.current_file() {
file
} else {
return;
}
.buffer();
let current = match get_character_at(app_state, app_state.caret().text_position()) {
Some(c) => c,
_ => return,
};
let mut pos = Point::new(current.dest().x(), current.dest().y());
let mut position: CaretPosition = app_state.caret().position().clone();
buffer.insert(position.text_position(), '\n');
if let Some(rect) = get_text_character_rect('\n', renderer) {
pos = Point::new(
app_state.config().editor_left_margin(),
pos.y() + rect.height() as i32,
);
position = position.moved(0, 1, 0);
app_state.caret_mut().move_caret(position, pos.clone());
}
let new_file = EditorFile::new(
current_file_path(app_state),
buffer,
app_state.config().clone(),
);
app_state.replace_current_file(new_file);
}

View File

@ -1,9 +1,9 @@
use crate::app::app_state::AppState; pub use crate::app::app_state::AppState;
use crate::config::Config; pub use crate::config::Config;
use crate::renderer::Renderer; pub use crate::renderer::Renderer;
use crate::themes::*; use crate::themes::*;
use crate::ui::caret::{CaretPosition, MoveDirection};
use crate::ui::*; use crate::ui::*;
use crate::ui::caret::{CaretPosition,MoveDirection};
use std::rc::Rc; use std::rc::Rc;
use std::thread::sleep; use std::thread::sleep;
@ -22,6 +22,8 @@ use sdl2::EventPump;
use sdl2::{Sdl, TimerSubsystem, VideoSubsystem}; use sdl2::{Sdl, TimerSubsystem, VideoSubsystem};
pub mod app_state; pub mod app_state;
pub mod caret_manager;
pub mod file_content_manager;
pub type WindowCanvas = Canvas<Window>; pub type WindowCanvas = Canvas<Window>;
@ -202,4 +204,8 @@ impl Application {
} }
UpdateResult::NoOp UpdateResult::NoOp
} }
pub fn config(&self) -> &Rc<Config> {
&self.config
}
} }

View File

@ -15,6 +15,10 @@ pub fn create() {
.unwrap_or_else(|_| panic!("Cannot create fonts config directory")); .unwrap_or_else(|_| panic!("Cannot create fonts config directory"));
write_default_fonts(); write_default_fonts();
} }
if !log_dir().exists() {
fs::create_dir_all(&log_dir()).unwrap_or_else(|_| panic!("Cannot create log directory"));
}
} }
fn write_default_fonts() { fn write_default_fonts() {

View File

@ -1,6 +1,12 @@
use dirs; use dirs;
use std::path::PathBuf; use std::path::PathBuf;
pub fn log_dir() -> PathBuf {
let mut log_dir = config_dir();
log_dir.push("log");
log_dir
}
pub fn themes_dir() -> PathBuf { pub fn themes_dir() -> PathBuf {
let mut themes_dir = config_dir(); let mut themes_dir = config_dir();
themes_dir.push("themes"); themes_dir.push("themes");

View File

@ -1,10 +1,14 @@
use crate::lexer::Language;
use crate::themes::Theme; use crate::themes::Theme;
use dirs; use dirs;
use std::collections::HashMap;
use std::fs; use std::fs;
mod creator; mod creator;
pub mod directories; pub mod directories;
type LanguageMapping = HashMap<String, Language>;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct EditorConfig { pub struct EditorConfig {
character_size: u16, character_size: u16,
@ -19,7 +23,7 @@ impl EditorConfig {
let mut default_font_path = directories::fonts_dir(); let mut default_font_path = directories::fonts_dir();
default_font_path.push("DejaVuSansMono.ttf"); default_font_path.push("DejaVuSansMono.ttf");
Self { Self {
character_size: 24, character_size: 16,
font_path: default_font_path.to_str().unwrap().to_string(), font_path: default_font_path.to_str().unwrap().to_string(),
current_theme: "railscasts".to_string(), current_theme: "railscasts".to_string(),
margin_left: 10, margin_left: 10,
@ -55,18 +59,25 @@ pub struct Config {
menu_height: u16, menu_height: u16,
editor_config: EditorConfig, editor_config: EditorConfig,
theme: Theme, theme: Theme,
extensions_mapping: LanguageMapping,
} }
impl Config { impl Config {
pub fn new() -> Self { pub fn new() -> Self {
creator::create(); creator::create();
let editor_config = EditorConfig::new(); let editor_config = EditorConfig::new();
let mut extensions_mapping = HashMap::new();
extensions_mapping.insert(".".to_string(), Language::PlainText);
extensions_mapping.insert("txt".to_string(), Language::PlainText);
extensions_mapping.insert("rs".to_string(), Language::Rust);
Self { Self {
width: 1024, width: 1024,
height: 860, height: 860,
menu_height: 60, menu_height: 60,
theme: Theme::load(editor_config.current_theme().clone()), theme: Theme::load(editor_config.current_theme().clone()),
editor_config, editor_config,
extensions_mapping,
} }
} }
pub fn width(&self) -> u32 { pub fn width(&self) -> u32 {
@ -96,4 +107,8 @@ impl Config {
pub fn editor_left_margin(&self) -> i32 { pub fn editor_left_margin(&self) -> i32 {
self.editor_config().margin_left() as i32 self.editor_config().margin_left() as i32
} }
pub fn extensions_mapping(&self) -> &LanguageMapping {
&self.extensions_mapping
}
} }

View File

@ -6,6 +6,7 @@ pub mod rust_lang;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Language { pub enum Language {
PlainText, PlainText,
Rust,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -144,11 +145,14 @@ impl Token {
} }
} }
pub fn parse(text: String, language: Language) -> Vec<TokenType> { pub fn parse(text: String, language: &Language) -> Vec<TokenType> {
match language { match language {
Language::PlainText => plain::lexer::Lexer::new(text.as_str()) &Language::PlainText => plain::lexer::Lexer::new(text.as_str())
// .inspect(|tok| println!("tok: {:?}", tok)) // .inspect(|tok| println!("tok: {:?}", tok))
.map(|t| t.0) .map(|t| t.0)
.collect(), .collect(),
&Language::Rust => rust_lang::lexer::Lexer::new(text.as_str())
.map(|t| t.0)
.collect(),
} }
} }

View File

@ -11,7 +11,11 @@ pub mod lexer {
token: Token::new(text.to_string(), 0, 0, 0, 0) token: Token::new(text.to_string(), 0, 0, 0, 0)
}, text), }, text),
r"(let|fn|type|struct|pub|impl|for|self|Self)" => (TokenType::Keyword { r"[+-/*%=]" => (TokenType::Operator {
token: Token::new(text.to_string(), 0, 0, 0, 0)
}, text),
r"(let|fn|type|struct|pub|impl|for|self|Self|mod|use|enum)" => (TokenType::Keyword {
token: Token::new(text.to_string(), 0, 0, 0, 0) token: Token::new(text.to_string(), 0, 0, 0, 0)
}, text), }, text),

View File

@ -10,8 +10,16 @@ extern crate serde;
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
#[macro_use]
extern crate log;
extern crate simplelog;
use crate::app::Application; use crate::app::Application;
use crate::config::directories::log_dir;
use log::Level;
use simplelog::*;
use std::fs::create_dir_all;
use std::fs::File;
pub mod app; pub mod app;
pub mod config; pub mod config;
@ -20,9 +28,28 @@ pub mod renderer;
pub mod themes; pub mod themes;
pub mod ui; pub mod ui;
fn init_logger() {
let mut log_file_path = log_dir();
log_file_path.push("rider.log");
CombinedLogger::init(vec![
TermLogger::new(LevelFilter::Warn, Config::default()).unwrap(),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create(log_file_path).unwrap(),
),
])
.unwrap();
}
fn main() { fn main() {
let mut app = Application::new(); let mut app = Application::new();
app.init(); app.init();
app.open_file("./tests/example.txt".to_string());
init_logger();
// app.open_file("./assets/examples/example.txt".to_string());
app.open_file("./assets/examples/test.rs".to_string());
app.run(); app.run();
} }

View File

@ -127,7 +127,7 @@ impl<'l> ResourceLoader<'l, Font<'l, 'static>> for Sdl2TtfContext {
type Args = FontDetails; type Args = FontDetails;
fn load(&'l self, data: &FontDetails) -> Result<Font<'l, 'static>, String> { fn load(&'l self, data: &FontDetails) -> Result<Font<'l, 'static>, String> {
println!("Loading font {}...", data.path); info!("Loading font {}...", data.path);
self.load_font(&data.path, data.size) self.load_font(&data.path, data.size)
} }
} }
@ -149,7 +149,9 @@ impl<'l, T> TextureManager<'l, T> {
let texture = self.loader.create_texture_from_surface(&surface).unwrap(); let texture = self.loader.create_texture_from_surface(&surface).unwrap();
let resource = Rc::new(texture); let resource = Rc::new(texture);
self.cache.insert(key, resource.clone()); self.cache.insert(key, resource.clone());
println!("texture for '{}' created", details.text); for c in details.text.chars() {
info!("texture for '{:?}' created", c);
}
Ok(resource) Ok(resource)
}, },
Ok, Ok,

View File

@ -102,9 +102,9 @@ fn railscasts_theme() -> Theme {
}, },
identifier: ThemeConfig { identifier: ThemeConfig {
color: SerdeColor { color: SerdeColor {
r: 21, r: 121,
g: 21, g: 121,
b: 21, b: 121,
a: 0, a: 0,
}, },
italic: false, italic: false,
@ -112,9 +112,9 @@ fn railscasts_theme() -> Theme {
}, },
literal: ThemeConfig { literal: ThemeConfig {
color: SerdeColor { color: SerdeColor {
r: 21, r: 121,
g: 21, g: 121,
b: 21, b: 121,
a: 0, a: 0,
}, },
italic: false, italic: false,
@ -142,9 +142,9 @@ fn railscasts_theme() -> Theme {
}, },
separator: ThemeConfig { separator: ThemeConfig {
color: SerdeColor { color: SerdeColor {
r: 21, r: 121,
g: 21, g: 121,
b: 21, b: 121,
a: 0, a: 0,
}, },
italic: false, italic: false,

View File

@ -6,8 +6,8 @@ use crate::ui::*;
use sdl2::pixels::Color; use sdl2::pixels::Color;
use sdl2::rect::{Point, Rect}; use sdl2::rect::{Point, Rect};
use sdl2::render::Texture; use sdl2::render::Texture;
use std::rc::Rc;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
enum CaretState { enum CaretState {
@ -20,7 +20,7 @@ pub enum MoveDirection {
Left, Left,
Right, Right,
Up, Up,
Down Down,
} }
//#[derive(Clone, Debug, PartialEq)] //#[derive(Clone, Debug, PartialEq)]
@ -42,11 +42,11 @@ pub struct CaretPosition {
} }
impl CaretPosition { impl CaretPosition {
pub fn new(text_position: usize, line_number: usize, line_position: usize,) -> Self { pub fn new(text_position: usize, line_number: usize, line_position: usize) -> Self {
Self { Self {
text_position, text_position,
line_number, line_number,
line_position line_position,
} }
} }
@ -80,11 +80,11 @@ impl CaretPosition {
self.line_position = n; self.line_position = n;
} }
pub fn moved(&self, text_position: usize, line_number: usize, line_position: usize) -> Self { pub fn moved(&self, text_position: i32, line_number: i32, line_position: i32) -> Self {
Self { Self {
text_position: self.text_position + text_position, text_position: (self.text_position as i32 + text_position) as usize,
line_number: self.line_number + line_number, line_number: (self.line_number as i32 + line_number) as usize,
line_position: self.line_position + line_position line_position: (self.line_position as i32 + line_position) as usize,
} }
} }
} }

View File

@ -19,9 +19,18 @@ pub struct EditorFile {
impl EditorFile { impl EditorFile {
pub fn new(path: String, buffer: String, config: Rc<Config>) -> Self { pub fn new(path: String, buffer: String, config: Rc<Config>) -> Self {
let sections = vec![EditorFileSection::new(buffer.clone(), config.clone())]; use std::path::Path;
let p = Path::new(&path);
let ext = match p.extension() {
Some(s) => s.to_str().unwrap_or("txt"),
None => "txt",
}
.to_string();
let sections = vec![EditorFileSection::new(buffer.clone(), ext, config.clone())];
let x = config.editor_left_margin(); let x = config.editor_left_margin();
let y = config.editor_top_margin(); let y = config.editor_top_margin();
Self { Self {
path, path,
sections, sections,

View File

@ -17,9 +17,14 @@ pub struct EditorFileSection {
} }
impl EditorFileSection { impl EditorFileSection {
pub fn new(buffer: String, config: Rc<Config>) -> Self { pub fn new(buffer: String, ext: String, config: Rc<Config>) -> Self {
use crate::lexer; use crate::lexer;
let lexer_tokens = lexer::parse(buffer.clone(), Language::PlainText);
let language = config
.extensions_mapping()
.get(ext.as_str())
.unwrap_or(&Language::PlainText);
let lexer_tokens = lexer::parse(buffer.clone(), language);
let mut tokens: Vec<EditorFileToken> = vec![]; let mut tokens: Vec<EditorFileToken> = vec![];
for token_type in lexer_tokens { for token_type in lexer_tokens {

View File

@ -45,21 +45,28 @@ impl EditorFileToken {
pub fn get_line(&self, line: &usize) -> Option<Vec<&TextCharacter>> { pub fn get_line(&self, line: &usize) -> Option<Vec<&TextCharacter>> {
let mut vec: Vec<&TextCharacter> = vec![]; let mut vec: Vec<&TextCharacter> = vec![];
for c in self.characters.iter() { for c in self.characters.iter() {
let _tmp = (line.clone(), c.line().clone(), self.token_type.is_new_line(), c.text_character()); let _tmp = (
match (line.clone(), c.line().clone(), self.token_type.is_new_line()) { line.clone(),
c.line().clone(),
self.token_type.is_new_line(),
c.text_character(),
);
match (
line.clone(),
c.line().clone(),
self.token_type.is_new_line(),
) {
(0, 0, true) => { (0, 0, true) => {
vec.push(c); vec.push(c);
}, }
(a, b, true) if (a + 1) == b => { (a, b, true) if (a + 1) == b => {
vec.push(c); vec.push(c);
}, }
(a, b, true) if a != (b + 1) => (a, b, true) if a != (b + 1) => (),
(),
(a, b, false) if a == b => { (a, b, false) if a == b => {
vec.push(c); vec.push(c);
} }
_t => _t => (),
(),
} }
} }
if vec.is_empty() { if vec.is_empty() {

View File

@ -1,10 +1,10 @@
use crate::app::{UpdateResult, WindowCanvas}; use crate::app::{UpdateResult, WindowCanvas};
use crate::config::Config; use crate::config::Config;
use crate::lexer::TokenType; use crate::lexer::TokenType;
use crate::renderer::managers::{TextDetails, FontDetails}; use crate::renderer::managers::{FontDetails, TextDetails};
use crate::renderer::Renderer; use crate::renderer::Renderer;
use crate::ui::*;
use crate::ui::caret::CaretPosition; use crate::ui::caret::CaretPosition;
use crate::ui::*;
use sdl2::pixels::Color; use sdl2::pixels::Color;
use sdl2::rect::{Point, Rect}; use sdl2::rect::{Point, Rect};
@ -168,11 +168,7 @@ impl ClickHandler for TextCharacter {
fn on_left_click(&mut self, _point: &Point) -> UpdateResult { fn on_left_click(&mut self, _point: &Point) -> UpdateResult {
UpdateResult::MoveCaret( UpdateResult::MoveCaret(
self.dest().clone(), self.dest().clone(),
CaretPosition::new( CaretPosition::new(self.position(), self.line(), 0),
self.position(),
self.line(),
0,
),
) )
} }