refactoring

main
Jordan Orelli 11 months ago
parent f39a22d408
commit 680adc5882

@ -1,7 +1,9 @@
use crate::log::*; use crate::log::*;
use std::cmp::min; use std::cmp::min;
pub struct Editor { /// An interactive text editor. The Editor is in control of all line editing functionality. It is a
/// type of text editor, albeit an extremely primitive one.
pub struct Buffer {
/// the current contents of the line /// the current contents of the line
chars: Vec<char>, chars: Vec<char>,
@ -9,7 +11,7 @@ pub struct Editor {
cursor: usize, cursor: usize,
} }
impl Editor { impl Buffer {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
chars: Vec::new(), chars: Vec::new(),
@ -17,6 +19,7 @@ impl Editor {
} }
} }
/// clears our edit buffer
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.cursor = 0; self.cursor = 0;
self.chars.clear(); self.chars.clear();

@ -1,5 +1,5 @@
use crate::{ use crate::{
edit::Editor, edit,
ext::{Command, Echo, Printenv, Tail, Which}, ext::{Command, Echo, Printenv, Tail, Which},
input, input,
log::*, log::*,
@ -8,7 +8,6 @@ use crate::{
use std::{ use std::{
error::Error, error::Error,
fmt,
io::{self, Write}, io::{self, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@ -16,10 +15,12 @@ use std::{
use anyhow::Result; use anyhow::Result;
use dirs; use dirs;
/// An interactive session. The Session object is the top-level object used to control an
/// interactive terminal session.
pub struct Session { pub struct Session {
pub input: input::Reader, pub input: input::Reader,
pub output: output::Writer, pub output: output::Writer,
pub editor: Editor, pub editor: edit::Buffer,
pub state: syntax::State, pub state: syntax::State,
} }
@ -28,7 +29,7 @@ impl Session {
Ok(Self { Ok(Self {
input: input::Reader::new()?, input: input::Reader::new()?,
output: output::Writer::stdout()?, output: output::Writer::stdout()?,
editor: Editor::new(), editor: edit::Buffer::new(),
state: syntax::State::new(), state: syntax::State::new(),
}) })
} }

Loading…
Cancel
Save