mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-24 16:14:45 +00:00
Create empty file if input doesn't exist
This commit is contained in:
parent
8072756990
commit
934634507d
4 changed files with 22 additions and 3 deletions
|
|
@ -50,18 +50,23 @@ class Buffer {
|
|||
|
||||
void remove(ulong start, ulong end) {
|
||||
text.remove(start, end);
|
||||
update();
|
||||
}
|
||||
void insert(ulong position, string value) {
|
||||
text.insert(position, value);
|
||||
update();
|
||||
}
|
||||
string substring(ulong start, ulong end = -1) {
|
||||
if (end == -1) {
|
||||
update();
|
||||
return text.substring(start, text.length);
|
||||
} else {
|
||||
update();
|
||||
return text.substring(start, end);
|
||||
}
|
||||
}
|
||||
char charAt(ulong pos) {
|
||||
update();
|
||||
return text.charAt(pos);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
src/main.d
16
src/main.d
|
|
@ -12,12 +12,24 @@ void main(string[] args) {
|
|||
|
||||
if (args.length > 1) {
|
||||
filename = args[1];
|
||||
fileTxt = readText(filename);
|
||||
if (!exists(filename)) {
|
||||
File file = File(filename, "w");
|
||||
file.close();
|
||||
} else {
|
||||
if (isDir(filename)) {
|
||||
writeln(filename, " is a directory");
|
||||
return;
|
||||
}
|
||||
fileTxt = readText(filename);
|
||||
if (fileTxt is null) {
|
||||
fileTxt = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buffer buf = new Buffer(fileTxt, filename);
|
||||
init();
|
||||
|
||||
Buffer buf = new Buffer(fileTxt, filename);
|
||||
Cursor cursor = new Cursor();
|
||||
View v = new View(buf, cursor);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ class Rope {
|
|||
void remove(ulong start, ulong end) {
|
||||
if (value !is null) {
|
||||
value = to!string(value.to!dstring[0 .. start] ~ value.to!dstring[end .. $]);
|
||||
if (value is null) {
|
||||
value = "";
|
||||
}
|
||||
length = value.count;
|
||||
} else {
|
||||
auto leftStart = min(start, left.length);
|
||||
|
|
|
|||
|
|
@ -152,7 +152,6 @@ class View {
|
|||
if (cursor.y > topline + height-1) {
|
||||
topline = cursor.y - height-1;
|
||||
}
|
||||
buf.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue