Skip to content

Commit

Permalink
Merge pull request #35 from curlpipe/0.2.5
Browse files Browse the repository at this point in the history
0.2.5
  • Loading branch information
curlpipe authored Oct 24, 2020
2 parents fa03456 + b340788 commit 256e5a4
Show file tree
Hide file tree
Showing 11 changed files with 1,034 additions and 883 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ox"
version = "0.2.4"
version = "0.2.5"
authors = ["Curly <[email protected]>"]
edition = "2018"
description = "A Rust powered text editor."
Expand All @@ -24,6 +24,6 @@ unicode-width = "0.1.8"
clap = "2.33.3"
shellexpand = "2.0.0"
ron = "0.6.2"
serde = "1.0.116"
regex = "1.3.9"
serde = "1.0.117"
regex = "1.4.1"
directories = "3.0.1"
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
Ox is a fast text editor that runs in your terminal.
<br><br>
<div align="center" style="display:inline;">
<img src="https://i.ibb.co/bs62TqT/image.png" width="49%">
<img src="https://i.ibb.co/c678HrM/image.png" width="49%">
<img src="https://i.postimg.cc/nrs9jksB/image.png" width="49%">
<img src="https://i.postimg.cc/KcQ0nv1Y/image.png" width="49%">
</div>
<br>
</p>
Expand Down Expand Up @@ -135,27 +135,24 @@ You can also use:

You can use the keys <kbd>Backspace</kbd> and <kbd>Return</kbd> / <kbd>Enter</kbd> as well as all the characters on your keyboard to edit files!

#### Saving the file

The simple keyboard shortcut of <kbd>Ctrl + S</kbd> can be used to save the current file and <kbd>Ctrl + W</kbd> can be used to "save as" the current file to a specific path.

#### Closing Ox

You can use the keybinding <kbd>Ctrl + Q</kbd> to exit Ox.

#### Searching a file in Ox

You can search both back and forth by activating the search feature through <kbd>Ctrl + F</kbd>, typing out what you wish to search and then using <kbd>→</kbd> or <kbd>↓</kbd> To search forward and <kbd>←</kbd> or <kbd>↑</kbd> to search backwards.

If at any time you wish to exit the search feature and return to the location in the document that you were in before activating the search feature, you can press <kbd>esc</kbd> on your keyboard, otherwise you can press any other key to exit the search feature and start editing your document at the new location.

#### Replacing

As with most text editors, Ox provides a replace / replace all feature <kbd>Ctrl + R</kbd> to replace individual occurances and <kbd>Ctrl + A</kbd> to replace all occurances at once. Regular expressions are supported in both commands.

#### Undoing / Redoing

Undoing and Redoing in Ox is as simple as <kbd>Ctrl + U</kbd> to undo and <kbd>Ctrl + Y</kbd> to redo. The changes are commited to the undo stack every time you press the space bar, create / destroy a new line and when there is inactivity longer than a specific period of time. (e.g. Ox will commit to the undo stack after 10 seconds of inactivity, possibly while you pause for thought or a break)
Ox is controlled via your keyboard shortcuts. Here are the default shortcuts that you can use:

| Keybinding | What it does |
| ------------ | ------------ |
| `Ctrl + Q` | Exits the current tab or the editor if only one tab open. |
| `Ctrl + S` | Saves the open file to the disk. |
| `Ctrl + W` | Prompts you for a file name and saves it to disk as that file name. |
| `Ctrl + P` | Saves all the currently open files to the disk. |
| `Ctrl + N` | Creates a new tab with a blank document. |
| `Ctrl + O` | Prompts you for a file and opens that file in a new tab. |
| `Ctrl + F` | Searches the document for a search query. Allows pressing of <kbd>↑</kbd> and <kbd>←</kbd> to move the cursor to the previous occurance fof the query and <kbd>↓</kbd> and <kbd>→</kbd> to move to the next occurance of the query. Press <kbd>Return</kbd> to cancel the search at the current cursor position or <kbd>Esc</kbd> to cancel the search and return to the initial location of the cursor. Note: this allows you to use regular expressions. |
| `Ctrl + U` | Undoes your last action. The changes are committed to the undo stack every time you press the space bar, create / destroy a new line and when there is no activity after a certain period of time which can be used to capture points where you pause for thought or grab a coffee etc... |
| `Ctrl + Y` | Redoes your last action. The changes are committed to the undo stack every time you press the space bar, create / destroy a new line and when there is no activity after a certain period of time which can be used to capture points where you pause for thought or grab a coffee etc... |
| `Ctrl + R` | Allows replacing of occurances in the document. Uses the same keybindings as the search feature: <kbd>↑</kbd> and <kbd>←</kbd> to move the cursor to the previous occurance fof the query and <kbd>↓</kbd> and <kbd>→</kbd> to move to the next occurance of the query. You can also press <kbd>Return</kbd>, <kbd>y</kbd> or <kbd>Space</kbd> to carry out the replace action. To exit replace mode once you're finished, you can press <kbd>Esc</kbd> to cancel and return back to your initial cursor position. Note: this allows you to use regular expressions. |
| `Ctrl + A` | Carries out a batch replace option. It will prompt you for a target to replace and what you want to replace it with and will then replace every occurance in the document. Note: this allows you to use regular expressions. |
| `Ctrl + D` | Navigates to the previous tab. |
| `Ctrl + H` | Navigates to the next tab. |

#### Configuring Ox

Expand Down Expand Up @@ -189,7 +186,7 @@ Here is the current summary
- [X] Config files (0.2.3)
- [X] Replacing text (0.2.3) [1549 lines]
- [X] Syntax highlighting (0.2.4) [1894 lines]
- [ ] Tabs for multitasking (0.2.5)
- [X] Tabs for multitasking (0.2.5) [2050 lines]
- [ ] Macros (0.2.6)
- [ ] Tweaks #1 (0.2.7)
- [ ] Tweaks #2 (0.2.8)
Expand Down
95 changes: 13 additions & 82 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,86 +33,6 @@ pub struct Reader {
impl Reader {
pub fn read(config: &str) -> (Self, Status) {
// Read the config file, if it fails, use a hard-coded configuration
let rust_kw = vec![
"as", "break", "const", "continue", "crate", "else", "enum", "extern", "fn", "for",
"if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref",
"return", "self", "static", "struct", "super", "trait", "type", "unsafe", "use",
"where", "while", "async", "await", "dyn", "abstract", "become", "box", "do", "final",
"macro", "override", "priv", "typeof", "unsized", "virtual", "yield", "try", "'static",
];
let default = Self {
general: General {
line_number_padding_right: 2,
line_number_padding_left: 1,
tab_width: 4,
undo_period: 5,
},
theme: Theme {
editor_bg: (41, 41, 61),
editor_fg: (255, 255, 255),
status_bg: (59, 59, 84),
status_fg: (35, 240, 144),
line_number_fg: (65, 65, 98),
},
highlights: [
("comments".to_string(), (113, 113, 169)),
("keywords".to_string(), (134, 76, 232)),
("strings".to_string(), (39, 222, 145)),
("characters".to_string(), (40, 198, 232)),
("digits".to_string(), (40, 198, 232)),
("booleans".to_string(), (86, 217, 178)),
("functions".to_string(), (47, 141, 252)),
("structs".to_string(), (47, 141, 252)),
("macros".to_string(), (223, 52, 249)),
("attributes".to_string(), (40, 198, 232)),
]
.iter()
.cloned()
.collect(),
languages: vec![Language {
name: "Rust".to_string(), // Name of the language
icon: "\u{e7a8} ".to_string(), // Icon for the language
extensions: vec!["rs".to_string()], // Extensions of the language
// Keywords of the language
keywords: rust_kw.iter().map(|x| (*x).to_string()).collect(),
// Syntax definitions
definitions: [
(
"comments".to_string(),
vec!["(?m)(//.*)$".to_string(), "(?ms)(/\\*.*?\\*/)".to_string()],
),
("strings".to_string(), vec!["(\".*?\")".to_string()]),
(
"characters".to_string(),
vec!["('.')".to_string(), "('\\\\.')".to_string()],
),
("digits".to_string(), vec!["(\\d+.\\d+|\\d+)".to_string()]),
(
"booleans".to_string(),
vec!["\\b(true|false)\\b".to_string()],
),
(
"functions".to_string(),
vec!["\\b\\s+([a-z_]*)\\b\\(".to_string()],
),
(
"structs".to_string(),
vec!["\\b([A-Z][A-Za-z_]*)\\b\\s*\\{".to_string()],
),
(
"macros".to_string(),
vec!["\\b([a-z_][a-zA-Z_]*!)".to_string()],
),
(
"attributes".to_string(),
vec!["^\\s*(#(?:!|)\\[.*?\\])".to_string()],
),
]
.iter()
.cloned()
.collect(),
}],
};
// Expand the path to get rid of any filepath issues
let config = if let Ok(config) = shellexpand::full(config) {
(*config).to_string()
Expand All @@ -127,12 +47,15 @@ impl Reader {
// There is a syntax issue with the config file
let result: Result<Self, ron::Error> = from_str(&file);
// Provide the syntax issue with the config file for debugging
(default, Status::Parse(format!("{:?}", result)))
(
from_str(DEFAULT).unwrap(),
Status::Parse(format!("{:?}", result)),
)
};
result
} else {
// File wasn't able to be found
(default, Status::File)
(from_str(DEFAULT).unwrap(), Status::File)
}
}
pub fn get_syntax_regex(config: &Self, extension: &str) -> Vec<TokenType> {
Expand Down Expand Up @@ -215,3 +138,11 @@ pub struct Language {
pub keywords: Vec<String>,
pub definitions: HashMap<String, Vec<String>>,
}

// Default configuration format
// Minify using:
// (| )//[a-zA-Z0-9 ]+ on https://www.regextester.com/
// https://codebeautify.org/text-minifier
const DEFAULT: &str = r#"
(general:General(line_number_padding_right:2,line_number_padding_left:1,tab_width:4,undo_period:5,),theme:Theme(editor_bg:(41,41,61),editor_fg:(255,255,255),status_bg:(59,59,84),status_fg:(35,240,144),line_number_fg:(65,65,98),),highlights:{"comments":(113,113,169),"keywords":(134,76,232),"references":(134,76,232),"strings":(39,222,145),"characters":(40,198,232),"digits":(40,198,232),"booleans":(86,217,178),"functions":(47,141,252),"structs":(47,141,252),"macros":(223,52,249),"attributes":(40,198,232),"headers":(47,141,252),"symbols":(47,141,252),"global":(86,217,178),},languages:[Language(name:"Rust",icon:"\u{e7a8}",extensions:["rs"],keywords:["as","break","const","continue","crate","else","enum","extern","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","static","struct","super","trait","type","unsafe","use","where","while","async","await","dyn","abstract","become","box","do","final","macro","override","priv","typeof","unsized","virtual","yield","try","'static","u8","u16","u32","u64","u128","usize","i8","i16","i32","i64","i128","isize","f32","f64","String","Vec","str","Some","bool","None","Box","Result","Option","Ok","Err",],definitions:{"comments":["(?m)(//.*)$","(?ms)(/\\*.*?\\*/)",],"strings":["(\".*?\")",],"characters":["('.')","('\\\\.')",],"digits":["\\b(\\d+.\\d+|\\d+)","\\b(\\d+.\\d+(?:f32|f64))",],"booleans":["\\b(true)\\b","\\b(false)\\b",],"functions":["fn\\s+([a-z_][A-Za-z0-9_]*)\\s*\\(",],"structs":["(?:trait|enum|struct|impl)\\s+([A-Z][A-Za-z0-9_]*)\\s*","impl(?:<.*?>|)\\s+([A-Z][A-Za-z0-9_]*)","([A-Z][A-Za-z0-9_]*)::","impl.*for\\s+([A-Z][A-Za-z0-9_]*)",],"macros":["\\b([a-z_][a-zA-Z0-9_]*!)",],"attributes":["^\\s*(#(?:!|)\\[.*?\\])",],"references":["&str","&mut","&self","&i8","&i16","&i32","&i64","&i128","&isize","&u8","&u16","&u32","&u64","&u128","&usize","&f32","&f64",]}),Language(name:"Ruby",icon:"\u{e739}",extensions:["rb"],keywords:["__ENCODING__","__LINE__","__FILE__","BEGIN","END","alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","print","for","if","in","module","next","nil","not","or","puts","redo","rescue","retry","return","self","super","then","undef","unless","until","when","while","yield","raise","include","extend",],definitions:{"comments":["(?m)(#.*)$","(?ms)(=begin.*=end)",],"strings":["((?:f|r|)\".*?\")","(\'.*?\')",],"digits":[r"\b(\d+.\d+|\d+)",],"booleans":[r"\b(true)\b",r"\b(false)\b",],"structs":[r"class(\s+[A-Za-z0-9_]*)",],"functions":[r"def\s+([a-z_][A-Za-z0-9_]*)",],"symbols":[r"(:[^,\)\.\s=]+)",],"global":[r"(\$[a-z_][A-Za-z0-9_]*)\s",]}),Language(name:"Crystal",icon:"\u{e7a3}",extensions:["cr"],keywords:["__ENCODING__","__LINE__","__FILE__","BEGIN","END","alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","print","for","if","in","module","next","nil","not","or","puts","redo","rescue","retry","return","self","super","then","undef","unless","until","when","while","yield","raise","include","extend","Int32","String","getter","setter","property",],definitions:{"comments":["(?m)(#.*)$","(?ms)(=begin.*=end)",],"strings":["(?ms)(\".*?\")","((?:f|r|)\".*?\")","(\'.*?\')",],"digits":[r"\b(\d+.\d+|\d+)",],"booleans":[r"\b(true)\b",r"\b(false)\b",],"structs":[r"class(\s+[A-Za-z0-9_]*)",],"functions":[r"def\s+([a-z_][A-Za-z0-9_]*)",],"symbols":[r"(:[^,\}\)\.\s=]+)",],"global":[r"(\$[a-z_][A-Za-z0-9_]*)\s",]}),Language(name:"Python",icon:"\u{e73c}",extensions:["py","pyw"],keywords:["and","as","assert","break","class","continue","def","del","elif","else","except","exec","finally","for","from","global","if","import","in","is","lambda","not","or","pass","print","raise","return","try","while","with","yield","str","bool","int","tuple","list","dict","tuple","len","None","input","type","set","range","enumerate","open","iter","min","max","dir","self","isinstance","help","next","super",],definitions:{"comments":["(?m)(#.*)$",],"strings":["(?ms)(\"\"\".*?\"\"\")","(?ms)(\'\'\'.*?\'\'\')","((?:f|r|)\".*?\")","(\'.*?\')",],"digits":["\\b(\\d+.\\d+|\\d+)",],"booleans":["\\b(True)\\b","\\b(False)\\b",],"structs":["class\\s+([A-Za-z0-9_]*)",],"functions":["def\\s+([a-z_][A-Za-z0-9_]*)",],"attributes":["@.*$",]}),Language(name:"Javascript",icon:"\u{e74e}",extensions:["js"],keywords:["abstract","arguments","await","boolean","break","byte","case","catch","char","class","const","continue","debugger","default","delete","do","double","else","enum","eval","export","extends","final","finally","float","for","of","function","goto","if","implements","import","in","instanceof","int","interface","let","long","native","new","null","package","private","protected","public","return","short","static","super","switch","synchronized","this","throw","throws","transient","try","typeof","var","void","volatile","console","while","with","yield","undefined","NaN","-Infinity","Infinity",],definitions:{"comments":["(?m)(//.*)$","(?ms)(/\\*.*\\*/)$",],"strings":["(?ms)(\"\"\".*?\"\"\")","(?ms)(\'\'\'.*?\'\'\')","((?:f|r|)\".*?\")","(\'.*?\')",],"digits":["\\b(\\d+.\\d+|\\d+)",],"booleans":["\\b(true)\\b","\\b(false)\\b",],"structs":["class\\s+([A-Za-z0-9_]*)",],"functions":["function\\s+([a-z_][A-Za-z0-9_]*)","\\b([a-z_][A-Za-z0-9_]*)\\s*\\("],}),Language(name:"C",icon:"\u{e61e}",extensions:["c","h"],keywords:["auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while","printf","fscanf","scanf","fputsf","exit","stderr","malloc","calloc","bool","realloc","free","strlen","size_t",],definitions:{"comments":["(?m)(//.*)$","(?ms)(/\\*.*?\\*/)",],"strings":["(\".*?\")",],"characters":["('.')","('\\\\.')",],"digits":["\\b(\\d+.\\d+|\\d+)","\\b(\\d+.\\d+(?:f|))",],"booleans":["\\b(true)\\b","\\b(false)\\b",],"functions":["(int|bool|void|char|double|long|short|size_t)\\s+([a-z_][A-Za-z0-9_]*)\\s*\\(",],"structs":["struct\\s+([A-Za-z0-9_]*)\\s*",],"attributes":["^\\s*(#.*?)\\s",],"headers":["(<.*?>)",],}),],)
"#;
Loading

0 comments on commit 256e5a4

Please sign in to comment.