Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow piping from stdin into a buffer on startup #996

Merged
merged 6 commits into from
Nov 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use crate::{
Document, DocumentId, View, ViewId,
};

use crossterm::tty::IsTty;
use futures_util::future;
use std::{
collections::BTreeMap,
io::stdin,
path::{Path, PathBuf},
pin::Pin,
sync::Arc,
Expand Down Expand Up @@ -311,7 +313,13 @@ impl Editor {
pub fn new_file(&mut self, action: Action) -> DocumentId {
let id = DocumentId(self.next_document_id);
self.next_document_id += 1;
let mut doc = Document::default();
let mut doc = if stdin().is_tty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want it to be in this function, I think it would make more sense for it to be in helix-term/src/application.rs::Application::new()

It did make me think of potentially opening new files that were piped from an application via :n "<shell stuff>" as a shortcut to creating a new file and directly piping it like that. @archseer

Document::default()
} else if let Ok((rope, encoding)) = crate::document::from_reader(&mut stdin(), None) {
Document::from(rope, Some(encoding))
} else {
Document::default()
};
doc.id = id;
self.documents.insert(id, doc);
self.switch(id, action);
Expand Down