@@ -3,7 +3,7 @@ use crossterm::{
3 cursor::position,
3 cursor::position,
4 event::{self, read, Event, EventStream, KeyCode, KeyEvent},
4 event::{self, read, Event, EventStream, KeyCode, KeyEvent},
5 execute, queue,
5 execute, queue,
6− style::Print,
6+ style::{Color, Print, SetForegroundColor},
7 terminal::{self, disable_raw_mode, enable_raw_mode},
7 terminal::{self, disable_raw_mode, enable_raw_mode},
9use futures::{future::FutureExt, select, StreamExt};
9use futures::{future::FutureExt, select, StreamExt};
@@ -16,25 +16,37 @@ use anyhow::Error;
16use crate::{keymap, Args};
16use crate::{keymap, Args};
17use helix_core::{Buffer, State};
17use helix_core::{Buffer, State};
19−pub struct View<'a> {
19+pub struct BufferComponent<'a> {
22− contents: &'a str,
22+ contents: Vec<&'a str>,
25−impl View<'_> {
25+impl BufferComponent<'_> {
26 pub fn render(&self) {
26 pub fn render(&self) {
27− execute!(
27+ let mut line_count = 0;
29− cursor::MoveTo(self.x, self.y),
30− Print(self.contents)
28+ for line in &self.contents {
31+ SetForegroundColor(Color::DarkCyan),
32+ cursor::MoveTo(self.x, self.y + line_count),
33+ Print((line_count + 1).to_string())
37+ SetForegroundColor(Color::Reset),
38+ cursor::MoveTo(self.x + 2, self.y + line_count),
35pub struct Editor {
47pub struct Editor {
36 state: Option<State>,
48 state: Option<State>,
37− current_line: u16,
49+ first_line: u16,
38 size: (u16, u16),
50 size: (u16, u16),
@@ -42,7 +54,7 @@ impl Editor {
42 pub fn new(mut args: Args) -> Result<Self, Error> {
54 pub fn new(mut args: Args) -> Result<Self, Error> {
43 let mut editor = Editor {
55 let mut editor = Editor {
44 state: None,
56 state: None,
45− current_line: 0,
57+ first_line: 0,
46 size: terminal::size().unwrap(),
58 size: terminal::size().unwrap(),
@@ -65,19 +77,17 @@ impl Editor {
66 match &self.state {
78 match &self.state {
67 Some(s) => {
79 Some(s) => {
68− for line in s
80+ let view = BufferComponent {
70− .lines_at(self.current_line as usize)
85+ .lines_at(self.first_line as usize)
71− .take(self.size.1 as usize)
86+ .take(self.size.1 as usize)
75− y: self.current_line,
76− contents: line.as_str().unwrap(),
87+ .map(|x| x.as_str().unwrap())
88+ .collect::<Vec<&str>>(),
78− view.render();
90+ view.render();
79− self.current_line += 1;
82 None => (),
92 None => (),