Skip to content

Commit

Permalink
Merge pull request #175 from curlpipe/0.6.9
Browse files Browse the repository at this point in the history
0.6.9
  • Loading branch information
curlpipe authored Oct 28, 2024
2 parents 610eab2 + 85f2c5e commit 68925d2
Show file tree
Hide file tree
Showing 26 changed files with 709 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion 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.8"
version = "0.6.9"
edition = "2021"
authors = ["Curlpipe <[email protected]>"]
description = "A Rust powered text editor."
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Heading -->
<!-- Heading -->
<br />
<p align="center">
<a href="https://github.com/curlpipe/ox/">
Expand All @@ -8,11 +8,11 @@
<h1 align="center" style="font-size: 50px;">Ox editor</h1>

<p align="center" style="font-size: 20px;">
Ox is a code editor that runs in your terminal.
The simple but flexible text editor
<br><br>
<div align="center" style="display:inline;">
<img src="https://i.postimg.cc/nrs9jksB/image.png" width="49%">
<img src="https://i.postimg.cc/KcQ0nv1Y/image.png" width="49%">
<img src="https://i.postimg.cc/zXB5y0r3/ox-blank.gif" width="49%">
<img src="https://i.postimg.cc/pVkRV33g/ox-code.gif" width="49%">
</div>
<br>
</p>
Expand All @@ -28,7 +28,7 @@ Ox is an independent text editor that can be used to write everything from text
If you're looking for a text editor that...
1. :feather: Is lightweight and efficient
2. :wrench: Can be configured to your heart's content
3. :package: Has features out of the box, including
3. :package: Has features out of the box, including
- syntax highlighting
- undo and redo
- search and replace
Expand All @@ -40,22 +40,22 @@ If you're looking for a text editor that...

It runs in your terminal as a text-user-interface, just like vim, nano and micro, however, it is not based on any existing editors and has been built from the ground up.

It is mainly used on linux systems, but macOS and Windows users (via WSL) are free to give it a go.
It is mainly designed on linux systems, but macOS and Windows users (via WSL) are free to give it a go. Work is currently underway to get it working perfectly on all systems.

## Selling Points

### Lightweight and Efficient

- :feather: Ox is lightweight, with the precompiled binary taking up roughly 4mb in storage space.
- :feather: Ox is lightweight, with the precompiled binary taking up roughly 5mb in storage space.
- :knot: It uses a `rope` data structure which allows incremental editing, file reading and file writing, which will speed up performance, particularly on huge files.
- :crab: It was built in Rust, which is a quick lower level language that has a strong reputation in the performance department.
- :crab: It was built in Rust, which is a quick lower-level language that has a strong reputation in the performance department.

### Strong configurability

- :electric_plug: Plug-In system where you can write your own plug-ins or integrate other people's
- :wrench: A wide number of options for configuration with everything from colours to the status line to syntax highlighting being open to customisation
- :moon: Ox uses Lua as a configuration language for familiarity when scripting and configuring
- 🤝 A configuration assistant to quickly get Ox set up for you from the get-go
- :handshake: A configuration assistant to quickly get Ox set up for you from the get-go

### Out of the box features

Expand Down Expand Up @@ -161,6 +161,8 @@ ox

This will open up an empty document.

However, if you've just downloaded Ox, the configuration assistant will automatically start up and help you configure the editor initially.

If you wish to open a file straight from the command line, you can run
```sh
ox /path/to/file
Expand Down Expand Up @@ -228,6 +230,8 @@ We've covered most keyboard shortcuts, but there are some other features you mig

Ox features a configuration system that allows the editor to be modified and personalised.

By default, you will be greeted by a configuration assistant when first starting Ox, when no configuration file is in place. This will help you generate a configuration file.

By default, Ox will look for a file here: `$XDG_CONFIG_HOME/.oxrc` or `~/.oxrc`.

On Windows, Ox will try to look here `C:/Users/user/ox/.oxrc` (where `user` is the user name of your account)
Expand All @@ -236,18 +240,16 @@ Ox's configuration language is [Lua](https://lua.org).

For reference, there is a default config in the `config` folder in the repository. You can either download it and place it in the default config directory or create your own using the example ones as a reference.

If you don't have a config file or don't want to mess around with it, don't worry, Ox has default settings it will use.

## Documentation

If you've been through the quick start guide above, but are looking for more detail, you can find in-depth documentation on the [wiki page](https://github.com/curlpipe/ox/wiki/)

This will take you step-by-step in great detail through 5 different stages:
This will take you step-by-step in great detail through 6 different stages:

1. **Installation** - advice and how-tos on installation
2. **Starting** - using the command line interface
3. **Using** - editing a document and controlling the editor
4. **Configuring** - writing plug-ins, changing the layout, adding to and changing the syntax highlighting
2. **Configuring** - changing the layout, adding to and changing the syntax highlighting
3. **General Editing** - editing a document and controlling the editor
4. **Command Line** - using the command line interface
5. **Plugins** - installing or uninstalling community plug-ins and writing or distributing your own plug-ins
6. **Roadmap** - planned features

Expand Down
73 changes: 51 additions & 22 deletions config/.oxrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ event_mapping = {
["pagedown"] = function()
editor:move_page_down()
end,
["esc"] = function()
editor:cancel_selection()
end,
["alt_v"] = function()
editor:cursor_to_viewport()
end,
["ctrl_g"] = function()
local line = editor:prompt("Go to line")
editor:move_to(0, tonumber(line))
Expand Down Expand Up @@ -116,30 +122,54 @@ event_mapping = {
editor:open_command_line()
end,
["alt_up"] = function()
-- current line information
local line = editor:get_line()
local cursor = editor.cursor
-- insert a new line
editor:insert_line_at(line, cursor.y - 1)
-- delete old copy and reposition cursor
editor:remove_line_at(cursor.y + 1)
-- restore cursor position
editor:move_to(cursor.x, cursor.y - 1)
-- correct indentation level
autoindent:fix_indent()
local select = editor.selection
local single = select.x == cursor.x and select.y == cursor.y
if single then
-- move single line
editor:move_line_up()
autoindent:fix_indent()
else
-- move an entire selection
if cursor.y > select.y then
for line = select.y, cursor.y do
editor:move_to(cursor.x, line)
editor:move_line_up()
end
else
for line = cursor.y, select.y do
editor:move_to(cursor.x, line)
editor:move_line_up()
end
end
editor:move_to(cursor.x, cursor.y - 1)
editor:select_to(select.x, select.y - 1)
end
end,
["alt_down"] = function()
-- current line information
local line = editor:get_line()
local cursor = editor.cursor
-- insert a new line
editor:insert_line_at(line, cursor.y + 2)
-- delete old copy and reposition cursor
editor:remove_line_at(cursor.y)
-- restore cursor position
editor:move_to(cursor.x, cursor.y + 1)
-- correct indentation level
autoindent:fix_indent()
local select = editor.selection
local single = select.x == cursor.x and select.y == cursor.y
if single then
-- move single line
editor:move_line_down()
autoindent:fix_indent()
else
-- move an entire selection
if cursor.y > select.y then
for line = cursor.y, select.y, -1 do
editor:move_to(cursor.x, line)
editor:move_line_down()
end
else
for line = select.y, cursor.y, -1 do
editor:move_to(cursor.x, line)
editor:move_line_down()
end
end
editor:move_to(cursor.x, cursor.y + 1)
editor:select_to(select.x, select.y + 1)
end
end,
["ctrl_w"] = function()
editor:remove_word()
Expand Down Expand Up @@ -309,5 +339,4 @@ syntax:set("deletion", {255, 100, 100}) -- Lists in various markup languages e.g
-- Import plugins (must be at the bottom of this file)
load_plugin("pairs.lua")
load_plugin("autoindent.lua")
--load_plugin("pomodoro.lua")
--load_plugin("update_notification.lua")
load_plugin("quickcomment.lua")
42 changes: 39 additions & 3 deletions kaolinite/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Document {
self.file.insert(idx, st);
// Update cache
let line: String = self.file.line(loc.y).chars().collect();
self.lines[loc.y] = line.trim_end_matches(&['\n', '\r']).to_string();
self.lines[loc.y] = line.trim_end_matches(['\n', '\r']).to_string();
// Update unicode map
let dbl_start = self.dbl_map.shift_insertion(loc, st, self.tab_width);
let tab_start = self.tab_map.shift_insertion(loc, st, self.tab_width);
Expand Down Expand Up @@ -341,7 +341,7 @@ impl Document {
self.file.remove(start..end);
// Update cache
let line: String = self.file.line(y).chars().collect();
self.lines[y] = line.trim_end_matches(&['\n', '\r']).to_string();
self.lines[y] = line.trim_end_matches(['\n', '\r']).to_string();
self.old_cursor = self.loc().x;
Ok(())
}
Expand Down Expand Up @@ -432,6 +432,36 @@ impl Document {
Ok(())
}

/// Swap a line upwards
/// # Errors
/// When out of bounds
pub fn swap_line_up(&mut self) -> Result<()> {
let cursor = self.char_loc();
let line = self.line(cursor.y).ok_or(Error::OutOfRange)?;
self.insert_line(cursor.y.saturating_sub(1), line)?;
self.delete_line(cursor.y + 1)?;
self.move_to(&Loc {
x: cursor.x,
y: cursor.y.saturating_sub(1),
});
Ok(())
}

/// Swap a line downwards
/// # Errors
/// When out of bounds
pub fn swap_line_down(&mut self) -> Result<()> {
let cursor = self.char_loc();
let line = self.line(cursor.y).ok_or(Error::OutOfRange)?;
self.insert_line(cursor.y + 2, line)?;
self.delete_line(cursor.y)?;
self.move_to(&Loc {
x: cursor.x,
y: cursor.y + 1,
});
Ok(())
}

/// Cancels the current selection
pub fn cancel_selection(&mut self) {
self.cursor.selection_end = self.cursor.loc;
Expand Down Expand Up @@ -953,6 +983,8 @@ impl Document {
// Bounds checking
if self.loc().y != y && y <= self.len_lines() {
self.cursor.loc.y = y;
} else if y > self.len_lines() {
self.cursor.loc.y = self.len_lines();
}
// Snap to end of line
self.fix_dangling_cursor();
Expand Down Expand Up @@ -1140,7 +1172,7 @@ impl Document {
self.tab_map.insert(i, tab_map);
// Cache this line
self.lines
.push(line.trim_end_matches(&['\n', '\r']).to_string());
.push(line.trim_end_matches(['\n', '\r']).to_string());
}
// Store new loaded point
self.info.loaded_to = to;
Expand Down Expand Up @@ -1297,17 +1329,21 @@ impl Document {
self.file.slice(self.selection_range()).to_string()
}

/// Commit a change to the undo management system
pub fn commit(&mut self) {
let s = self.take_snapshot();
self.undo_mgmt.backpatch_cursor(&self.cursor);
self.undo_mgmt.commit(s);
}

/// Completely reload the file
pub fn reload_lines(&mut self) {
let to = std::mem::take(&mut self.info.loaded_to);
self.lines.clear();
self.load_to(to);
}

/// Delete the currently selected text
pub fn remove_selection(&mut self) {
self.file.remove(self.selection_range());
self.reload_lines();
Expand Down
7 changes: 7 additions & 0 deletions kaolinite/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,11 @@ impl UndoMgmt {
pub fn at_file(&self) -> bool {
self.undo.len() == self.on_disk
}

/// Change the cursor position of the previous snapshot
pub fn backpatch_cursor(&mut self, cursor: &Cursor) {
if let Some(snapshot) = self.undo.last_mut() {
snapshot.cursor = *cursor;
}
}
}
Loading

0 comments on commit 68925d2

Please sign in to comment.