aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorJason Hansen2021-11-10 01:53:14 +0000
committerGitHub2021-11-10 01:53:14 +0000
commitcf831b1a65625f29d6e1bc12483a45c1adc8dff4 (patch)
treed5927e05d2cf0e3e074774276432504fd506d558 /helix-view/src
parent68224232af1126daa5b043a096269fbd6cb53551 (diff)
Allow piping from stdin into a buffer on startup (#996)
* Allow piping from stdin into a buffer on startup * Refactor * Don't allow piping into new buffer on macOS * Update helix-term/src/application.rs Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> * Update helix-term/src/application.rs Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> * Fix Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 631dcf0c..7650d217 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -9,6 +9,7 @@ use crate::{
use futures_util::future;
use std::{
collections::BTreeMap,
+ io::stdin,
path::{Path, PathBuf},
pin::Pin,
sync::Arc,
@@ -314,16 +315,24 @@ impl Editor {
self._refresh();
}
- pub fn new_file(&mut self, action: Action) -> DocumentId {
+ fn new_file_from_document(&mut self, action: Action, mut document: Document) -> DocumentId {
let id = DocumentId(self.next_document_id);
self.next_document_id += 1;
- let mut doc = Document::default();
- doc.id = id;
- self.documents.insert(id, doc);
+ document.id = id;
+ self.documents.insert(id, document);
self.switch(id, action);
id
}
+ pub fn new_file(&mut self, action: Action) -> DocumentId {
+ self.new_file_from_document(action, Document::default())
+ }
+
+ pub fn new_file_from_stdin(&mut self, action: Action) -> Result<DocumentId, Error> {
+ let (rope, encoding) = crate::document::from_reader(&mut stdin(), None)?;
+ Ok(self.new_file_from_document(action, Document::from(rope, Some(encoding))))
+ }
+
pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
let path = helix_core::path::get_canonicalized_path(&path)?;