Skip to content

Commit

Permalink
Merge pull request #180 from curlpipe/0.7.0
Browse files Browse the repository at this point in the history
0.7.0
  • Loading branch information
curlpipe authored Nov 7, 2024
2 parents 6c78450 + 40cb033 commit 8d2ad72
Show file tree
Hide file tree
Showing 27 changed files with 894 additions and 445 deletions.
52 changes: 11 additions & 41 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude = ["cactus"]

[package]
name = "ox"
version = "0.6.10"
version = "0.7.0"
edition = "2021"
authors = ["Curlpipe <[email protected]>"]
description = "A Rust powered text editor."
Expand All @@ -28,6 +28,7 @@ assets = [
]

#[profile.release]
#debug = true
#lto = true
#panic = "abort"
#codegen-units = 1
Expand All @@ -38,7 +39,7 @@ base64 = "0.22.1"
crossterm = "0.28.1"
jargon-args = "0.2.7"
kaolinite = { path = "./kaolinite" }
mlua = { version = "0.9.9", features = ["lua54", "vendored"] }
error_set = "0.6"
mlua = { version = "0.10", features = ["lua54", "vendored"] }
error_set = "0.7"
shellexpand = "3.1.0"
synoptic = "2.2.1"
synoptic = "2.2.6"
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cargo deb
cp target/debian/*.deb target/pkgs/

# Build for macOS (binary)
export SDKROOT=../../make/MacOSX13.3.sdk/
export SDKROOT=/home/luke/dev/make/MacOSX13.3.sdk/
export PATH=$PATH:~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=rust-lld
cargo zigbuild --release --target x86_64-apple-darwin
Expand Down
21 changes: 21 additions & 0 deletions config/.oxrc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ event_mapping = {
["ctrl_w"] = function()
editor:remove_word()
end,
-- Macros
["ctrl_esc"] = function()
editor:macro_record_stop()
editor:display_info("Macro recorded")
end,
}

-- Define user-defined commands
Expand Down Expand Up @@ -303,6 +308,22 @@ commands = {
editor:reload_config()
editor:display_info("Configuration file reloaded")
end,
["macro"] = function(arguments)
if arguments[1] == "record" then
editor:macro_record_start()
editor:display_info("Recording macro, press ctrl+esc to stop")
elseif arguments[1] == "play" then
local reps
if arguments[2] == nil then
reps = 1
else
reps = tonumber(arguments[2])
end
editor:macro_play(reps)
else
editor:display_error(tostring(arguments[1]) .. " is not a valid macro command")
end
end,
}

-- Configure Documents --
Expand Down
4 changes: 2 additions & 2 deletions kaolinite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ keywords = ["unicode", "text-processing"]
categories = ["text-processing"]

[dependencies]
error_set = "0.6"
regex = "1.10.6"
error_set = "0.7"
regex = "1"
ropey = "1.6.1"
unicode-width = "0.2"

Expand Down
22 changes: 22 additions & 0 deletions kaolinite/src/document/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl Document {

/// Move up by 1 page
pub fn move_page_up(&mut self) {
self.clear_cursors();
// Set x to 0
self.cursor.loc.x = 0;
self.char_ptr = 0;
Expand All @@ -201,6 +202,7 @@ impl Document {

/// Move down by 1 page
pub fn move_page_down(&mut self) {
self.clear_cursors();
// Set x to 0
self.cursor.loc.x = 0;
self.char_ptr = 0;
Expand Down Expand Up @@ -399,4 +401,24 @@ impl Document {
pub fn cancel_selection(&mut self) {
self.cursor.selection_end = self.cursor.loc;
}

/// Create a new alternative cursor
pub fn new_cursor(&mut self, loc: Loc) {
if let Some(idx) = self.has_cursor(loc) {
self.secondary_cursors.remove(idx);
} else if self.out_of_range(loc.x, loc.y).is_ok() {
self.secondary_cursors.push(loc);
}
}

/// Clear all secondary cursors
pub fn clear_cursors(&mut self) {
self.secondary_cursors.clear();
}

/// Determine if there is a secondary cursor at a certain position
#[must_use]
pub fn has_cursor(&self, loc: Loc) -> Option<usize> {
self.secondary_cursors.iter().position(|c| *c == loc)
}
}
2 changes: 2 additions & 0 deletions kaolinite/src/document/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Document {
eol: false,
read_only: false,
},
secondary_cursors: vec![],
}
}

Expand Down Expand Up @@ -77,6 +78,7 @@ impl Document {
tab_width: 4,
old_cursor: 0,
in_redo: false,
secondary_cursors: vec![],
})
}

Expand Down
15 changes: 12 additions & 3 deletions kaolinite/src/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct Document {
pub in_redo: bool,
/// The number of spaces a tab should be rendered as
pub tab_width: usize,
/// Secondary cursor (for multi-cursors)
pub secondary_cursors: Vec<Loc>,
}

impl Document {
Expand Down Expand Up @@ -113,6 +115,7 @@ impl Document {
/// # Errors
/// Returns an error if there is a problem with the specified operation.
pub fn forth(&mut self, ev: Event) -> Result<()> {
// Perform the event
match ev {
Event::Insert(loc, ch) => self.insert(&loc, &ch),
Event::Delete(loc, st) => self.delete_with_tab(&loc, &st),
Expand Down Expand Up @@ -256,9 +259,15 @@ impl Document {
// Account for double width characters
idx = idx.saturating_sub(self.dbl_map.count(loc, true).unwrap_or(0));
// Account for tab characters
idx = idx.saturating_sub(
self.tab_map.count(loc, true).unwrap_or(0) * self.tab_width.saturating_sub(1),
);
let tabs_behind = self.tab_map.count(loc, true).unwrap_or(0);
idx = if let Some(inner_idx) = self.tab_map.inside(self.tab_width, loc.x, loc.y) {
// Display index is within a tab, account for it properly
let existing_tabs = tabs_behind.saturating_sub(1) * self.tab_width.saturating_sub(1);
idx.saturating_sub(existing_tabs + inner_idx)
} else {
// Display index isn't in a tab
idx.saturating_sub(tabs_behind * self.tab_width.saturating_sub(1))
};
idx
}

Expand Down
13 changes: 13 additions & 0 deletions kaolinite/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use unicode_width::UnicodeWidthChar;

/// This is a type for making a note of the location of different characters
/// `HashMap`<`y_pos`, Vec<(display, character)>>
type CharHashMap = HashMap<usize, Vec<(usize, usize)>>;

/// Keeps notes of specific characters within a document for the purposes of double width and
Expand Down Expand Up @@ -166,6 +167,18 @@ impl CharMap {
}
Some(ctr)
}

/// If all character maps are of size n, then determine if x would be within one,
/// and return their index inside the mapped char
#[must_use]
pub fn inside(&self, n: usize, x: usize, y: usize) -> Option<usize> {
for (disp, _) in self.get(y)? {
if ((disp + 1)..(disp + n)).contains(&x) {
return Some(x.saturating_sub(*disp));
}
}
None
}
}

/// Vector that takes two usize values
Expand Down
53 changes: 26 additions & 27 deletions src/config/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crossterm::execute;
use crossterm::style::{SetBackgroundColor as Bg, SetForegroundColor as Fg};
use crossterm::terminal::{Clear, ClearType};
use mlua::prelude::*;
use std::cell::RefCell;
use std::io::{stdout, Write};
use std::rc::Rc;

pub const TROPICAL: &str = include_str!("../../plugins/themes/tropical.lua");
pub const GALAXY: &str = include_str!("../../plugins/themes/galaxy.lua");
Expand Down Expand Up @@ -571,14 +569,14 @@ impl Assistant {
pub fn demonstrate_theme(name: &str, code: &str) -> Result<String> {
// Create an environment to capture all the values
let lua = Lua::new();
let colors = Rc::new(RefCell::new(Colors::default()));
let syntax_highlighting = Rc::new(RefCell::new(SyntaxHighlighting::default()));
let colors = lua.create_userdata(Colors::default())?;
let syntax_highlighting = lua.create_userdata(SyntaxHighlighting::default())?;
lua.globals().set("syntax", syntax_highlighting.clone())?;
lua.globals().set("colors", colors.clone())?;
// Access all the values
lua.load(code).exec()?;
// Gather the editor colours
let col = colors.borrow();
let col: LuaUserDataRef<Colors> = colors.borrow()?;
let editor = format!(
"{}{}",
Fg(col.editor_fg.to_color()?),
Expand Down Expand Up @@ -625,28 +623,29 @@ impl Assistant {
Bg(col.info_bg.to_color()?)
);
// Gather syntax highlighting colours
let string = Fg(syntax_highlighting.borrow().get_theme("string")?);
let comment = Fg(syntax_highlighting.borrow().get_theme("comment")?);
let digit = Fg(syntax_highlighting.borrow().get_theme("digit")?);
let keyword = Fg(syntax_highlighting.borrow().get_theme("keyword")?);
let character = Fg(syntax_highlighting.borrow().get_theme("character")?);
let type_syn = Fg(syntax_highlighting.borrow().get_theme("type")?);
let function = Fg(syntax_highlighting.borrow().get_theme("function")?);
let macro_syn = Fg(syntax_highlighting.borrow().get_theme("macro")?);
let block = Fg(syntax_highlighting.borrow().get_theme("block")?);
let namespace = Fg(syntax_highlighting.borrow().get_theme("namespace")?);
let header = Fg(syntax_highlighting.borrow().get_theme("header")?);
let struct_syn = Fg(syntax_highlighting.borrow().get_theme("struct")?);
let operator = Fg(syntax_highlighting.borrow().get_theme("operator")?);
let boolean = Fg(syntax_highlighting.borrow().get_theme("boolean")?);
let reference = Fg(syntax_highlighting.borrow().get_theme("reference")?);
let tag = Fg(syntax_highlighting.borrow().get_theme("tag")?);
let heading = Fg(syntax_highlighting.borrow().get_theme("heading")?);
let link = Fg(syntax_highlighting.borrow().get_theme("link")?);
let bold = Fg(syntax_highlighting.borrow().get_theme("bold")?);
let italic = Fg(syntax_highlighting.borrow().get_theme("italic")?);
let insertion = Fg(syntax_highlighting.borrow().get_theme("insertion")?);
let deletion = Fg(syntax_highlighting.borrow().get_theme("deletion")?);
let syn: LuaUserDataRef<SyntaxHighlighting> = syntax_highlighting.borrow()?;
let string = Fg(syn.get_theme("string")?);
let comment = Fg(syn.get_theme("comment")?);
let digit = Fg(syn.get_theme("digit")?);
let keyword = Fg(syn.get_theme("keyword")?);
let character = Fg(syn.get_theme("character")?);
let type_syn = Fg(syn.get_theme("type")?);
let function = Fg(syn.get_theme("function")?);
let macro_syn = Fg(syn.get_theme("macro")?);
let block = Fg(syn.get_theme("block")?);
let namespace = Fg(syn.get_theme("namespace")?);
let header = Fg(syn.get_theme("header")?);
let struct_syn = Fg(syn.get_theme("struct")?);
let operator = Fg(syn.get_theme("operator")?);
let boolean = Fg(syn.get_theme("boolean")?);
let reference = Fg(syn.get_theme("reference")?);
let tag = Fg(syn.get_theme("tag")?);
let heading = Fg(syn.get_theme("heading")?);
let link = Fg(syn.get_theme("link")?);
let bold = Fg(syn.get_theme("bold")?);
let italic = Fg(syn.get_theme("italic")?);
let insertion = Fg(syn.get_theme("insertion")?);
let deletion = Fg(syn.get_theme("deletion")?);
// Render the preview
let name = format!(" {name} ");
Ok(format!("{name:─^47}
Expand Down
Loading

0 comments on commit 8d2ad72

Please sign in to comment.