mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 15:25:42 -04:00
Add statusline and accept pipes from stdin
This commit is contained in:
parent
934634507d
commit
757986ae3f
@ -14,6 +14,7 @@ class Buffer {
|
|||||||
|
|
||||||
this(string txt, string path) {
|
this(string txt, string path) {
|
||||||
text = new Rope(txt);
|
text = new Rope(txt);
|
||||||
|
savedText = txt;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,4 @@ class Cursor {
|
|||||||
void hide() {
|
void hide() {
|
||||||
x = y = -1;
|
x = y = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void display() {
|
|
||||||
setCursor(x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,12 @@ void main(string[] args) {
|
|||||||
fileTxt = "";
|
fileTxt = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (stdin.size != 0) {
|
||||||
|
foreach (line; stdin.byLine()) {
|
||||||
|
fileTxt ~= line ~ "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer buf = new Buffer(fileTxt, filename);
|
Buffer buf = new Buffer(fileTxt, filename);
|
||||||
@ -41,7 +47,6 @@ void main(string[] args) {
|
|||||||
clear();
|
clear();
|
||||||
|
|
||||||
v.display();
|
v.display();
|
||||||
cursor.display();
|
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
pollEvent(&e);
|
pollEvent(&e);
|
||||||
|
29
src/statusline.d
Normal file
29
src/statusline.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import termbox;
|
||||||
|
import view;
|
||||||
|
|
||||||
|
class StatusLine {
|
||||||
|
View view;
|
||||||
|
|
||||||
|
this(View v) {
|
||||||
|
this.view = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void display() {
|
||||||
|
int y = view.height;
|
||||||
|
string file = view.buf.path;
|
||||||
|
if (file == "") {
|
||||||
|
file = "untitled";
|
||||||
|
}
|
||||||
|
if (view.buf.toString != view.buf.savedText) {
|
||||||
|
file ~= " +";
|
||||||
|
}
|
||||||
|
file ~= " (" ~ to!string(view.cursor.y + 1) ~ "," ~ to!string(view.cursor.x + 1) ~ ")";
|
||||||
|
foreach (x; 0 .. view.width) {
|
||||||
|
if (x >= 1 && x < 1 + file.length) {
|
||||||
|
setCell(x, y, cast(uint) file[x - 1], Color.black, Color.blue);
|
||||||
|
} else {
|
||||||
|
setCell(x, y, ' ', Color.black, Color.blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/view.d
23
src/view.d
@ -2,6 +2,7 @@ import termbox;
|
|||||||
import buffer;
|
import buffer;
|
||||||
import clipboard;
|
import clipboard;
|
||||||
import cursor;
|
import cursor;
|
||||||
|
import statusline;
|
||||||
|
|
||||||
import std.conv: to;
|
import std.conv: to;
|
||||||
import std.utf: count;
|
import std.utf: count;
|
||||||
@ -14,6 +15,7 @@ class View {
|
|||||||
|
|
||||||
Buffer buf;
|
Buffer buf;
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
|
StatusLine sl;
|
||||||
|
|
||||||
this(Buffer buf, Cursor cursor, uint topline = 0, uint width = termbox.width(), uint height = termbox.height() - 2) {
|
this(Buffer buf, Cursor cursor, uint topline = 0, uint width = termbox.width(), uint height = termbox.height() - 2) {
|
||||||
this.topline = topline;
|
this.topline = topline;
|
||||||
@ -22,6 +24,7 @@ class View {
|
|||||||
|
|
||||||
this.buf = buf;
|
this.buf = buf;
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
|
this.sl = new StatusLine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint toCharNumber(int x, int y) {
|
uint toCharNumber(int x, int y) {
|
||||||
@ -111,7 +114,13 @@ class View {
|
|||||||
cursorLeft();
|
cursorLeft();
|
||||||
} else if (e.key == Key.mouseLeft) {
|
} else if (e.key == Key.mouseLeft) {
|
||||||
cursor.x = e.x;
|
cursor.x = e.x;
|
||||||
cursor.y = e.y;
|
cursor.y = e.y + topline;
|
||||||
|
if (cursor.y - topline > height-1) {
|
||||||
|
cursor.y = height + topline-1;
|
||||||
|
}
|
||||||
|
if (cursor.y > buf.lines.length) {
|
||||||
|
cursor.y = cast(int) buf.lines.length-1;
|
||||||
|
}
|
||||||
cursor.lastX = cursor.x;
|
cursor.lastX = cursor.x;
|
||||||
if (cursor.x > buf.lines[cursor.y].length) {
|
if (cursor.x > buf.lines[cursor.y].length) {
|
||||||
cursor.x = cast(int) buf.lines[cursor.y].length;
|
cursor.x = cast(int) buf.lines[cursor.y].length;
|
||||||
@ -155,7 +164,7 @@ class View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display() {
|
void display(bool drawCursor = true) {
|
||||||
uint x, y;
|
uint x, y;
|
||||||
|
|
||||||
string[] lines;
|
string[] lines;
|
||||||
@ -172,5 +181,15 @@ class View {
|
|||||||
y++;
|
y++;
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (drawCursor) {
|
||||||
|
if (cursor.y - topline < 0 || cursor.y - topline > height-1) {
|
||||||
|
hideCursor();
|
||||||
|
} else {
|
||||||
|
setCursor(cursor.x, cursor.y - topline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sl.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user