mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Working on text-editor
This commit is contained in:
@@ -21,6 +21,9 @@ Released on ??
|
|||||||
- Linux: `/home/alice/.config/termscp/bookmarks.toml`
|
- Linux: `/home/alice/.config/termscp/bookmarks.toml`
|
||||||
- Windows: `C:\Users\Alice\AppData\Roaming\termscp\bookmarks.toml`
|
- Windows: `C:\Users\Alice\AppData\Roaming\termscp\bookmarks.toml`
|
||||||
- MacOS: `/Users/Alice/Library/Application Support/termscp/bookmarks.toml`
|
- MacOS: `/Users/Alice/Library/Application Support/termscp/bookmarks.toml`
|
||||||
|
- **Text Editor**
|
||||||
|
- Added text editor feature to explorer view
|
||||||
|
- Added `o` to keybindings to open a text file
|
||||||
- Enhancements:
|
- Enhancements:
|
||||||
- User interface
|
- User interface
|
||||||
- Collpased borders to make everything more *aesthetic*
|
- Collpased borders to make everything more *aesthetic*
|
||||||
|
|||||||
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -196,6 +196,15 @@ version = "0.1.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "content_inspector"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@@ -318,6 +327,16 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "edit"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "323032447eba6f5aca88b46d6e7815151c16c53e4128569420c09d7840db3bfc"
|
||||||
|
dependencies = [
|
||||||
|
"tempfile",
|
||||||
|
"which",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -981,8 +1000,10 @@ version = "0.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytesize",
|
"bytesize",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"content_inspector",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"edit",
|
||||||
"ftp4",
|
"ftp4",
|
||||||
"getopts",
|
"getopts",
|
||||||
"hostname",
|
"hostname",
|
||||||
@@ -1187,6 +1208,15 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "which"
|
||||||
|
version = "3.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "whoami"
|
name = "whoami"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ readme = "README.md"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bytesize = "1.0.1"
|
bytesize = "1.0.1"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
|
content_inspector = "0.2.4"
|
||||||
crossterm = "0.18.2"
|
crossterm = "0.18.2"
|
||||||
dirs = "3.0.1"
|
dirs = "3.0.1"
|
||||||
|
edit = "0.1.2"
|
||||||
ftp4 = { version = "^4.0.1", features = ["secure"] }
|
ftp4 = { version = "^4.0.1", features = ["secure"] }
|
||||||
getopts = "0.2.21"
|
getopts = "0.2.21"
|
||||||
hostname = "0.3.1"
|
hostname = "0.3.1"
|
||||||
@@ -29,6 +31,7 @@ regex = "1.4.2"
|
|||||||
rpassword = "5.0.0"
|
rpassword = "5.0.0"
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
ssh2 = "0.9.0"
|
ssh2 = "0.9.0"
|
||||||
|
tempfile = "3.1.0"
|
||||||
textwrap = "0.13.0"
|
textwrap = "0.13.0"
|
||||||
toml = "0.5.7"
|
toml = "0.5.7"
|
||||||
tui = { version = "0.13.0", features = ["crossterm"], default-features = false }
|
tui = { version = "0.13.0", features = ["crossterm"], default-features = false }
|
||||||
@@ -38,9 +41,6 @@ whoami = "1.0.0"
|
|||||||
[target.'cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))'.dependencies]
|
[target.'cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))'.dependencies]
|
||||||
users = "0.11.0"
|
users = "0.11.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tempfile = "3"
|
|
||||||
|
|
||||||
#[patch.crates-io]
|
#[patch.crates-io]
|
||||||
#ftp = { git = "https://github.com/ChristianVisintin/rust-ftp" }
|
#ftp = { git = "https://github.com/ChristianVisintin/rust-ftp" }
|
||||||
|
|
||||||
|
|||||||
@@ -258,8 +258,6 @@ The developer documentation can be found on Rust Docs at <https://docs.rs/termsc
|
|||||||
|
|
||||||
## Upcoming Features 🧪
|
## Upcoming Features 🧪
|
||||||
|
|
||||||
- **Text editor**: possibility to open, read and write file both on remote and on local host; this will also support syntax highlighting.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Contributions 🤝🏻
|
## Contributions 🤝🏻
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
// Deps
|
// Deps
|
||||||
extern crate bytesize;
|
extern crate bytesize;
|
||||||
|
extern crate content_inspector;
|
||||||
|
extern crate crossterm;
|
||||||
|
|
||||||
// Locals
|
// Locals
|
||||||
use super::{FileTransferActivity, FsEntry, InputMode, LogLevel, PopupType};
|
use super::{FileTransferActivity, FsEntry, InputMode, LogLevel, PopupType};
|
||||||
@@ -28,6 +30,8 @@ use crate::utils::fmt_millis;
|
|||||||
|
|
||||||
// Ext
|
// Ext
|
||||||
use bytesize::ByteSize;
|
use bytesize::ByteSize;
|
||||||
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
||||||
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Seek, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
@@ -852,28 +856,62 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
self.log(
|
self.log_and_alert(
|
||||||
LogLevel::Error,
|
LogLevel::Error,
|
||||||
format!("Could not change working directory: {}", err).as_str(),
|
|
||||||
);
|
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
|
||||||
Color::Red,
|
|
||||||
format!("Could not change working directory: {}", err),
|
format!("Could not change working directory: {}", err),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
self.log(
|
self.log_and_alert(
|
||||||
LogLevel::Error,
|
LogLevel::Error,
|
||||||
format!("Could not change working directory: {}", err).as_str(),
|
|
||||||
);
|
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
|
||||||
Color::Red,
|
|
||||||
format!("Could not change working directory: {}", err),
|
format!("Could not change working directory: {}", err),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### edit_file
|
||||||
|
///
|
||||||
|
/// Edit a file on localhost
|
||||||
|
pub(super) fn edit_file(&mut self, path: &Path) {
|
||||||
|
// Read first 2048 bytes or less from file to check if it is textual
|
||||||
|
match OpenOptions::new().read(true).open(path) {
|
||||||
|
Ok(mut f) => {
|
||||||
|
// Read
|
||||||
|
let mut buff: [u8; 2048] = [0; 2048];
|
||||||
|
match f.read(&mut buff) {
|
||||||
|
Ok(_) => {
|
||||||
|
if content_inspector::inspect(&buff).is_binary() {
|
||||||
|
self.log_and_alert(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!("Could not open file in editor: file is binary"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.log_and_alert(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!("Could not read file: {}", err),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.log_and_alert(LogLevel::Error, format!("Could not read file: {}", err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Put input mode back to normal
|
||||||
|
let _ = disable_raw_mode();
|
||||||
|
// Open editor
|
||||||
|
if let Err(err) = edit::edit_file(path) {
|
||||||
|
self.log_and_alert(LogLevel::Error, format!("Could not open editor: {}", err));
|
||||||
|
}
|
||||||
|
// Re-enable raw mode
|
||||||
|
let _ = enable_raw_mode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user