]> git.lizzy.rs Git - micro.git/blob - src/main.d
Better tabs (still some issues)
[micro.git] / src / main.d
1 import termbox;
2 import buffer;
3 import cursor;
4 import view;
5 import clipboard;
6
7 import std.stdio;
8 import std.file: readText, exists, isDir;
9
10 void main(string[] args) {
11     string filename = "";
12     string fileTxt = "";
13
14     if (args.length > 1) {
15         filename = args[1];
16         if (exists(filename)) {
17             if (isDir(filename)) {
18                 writeln(filename, " is a directory");
19                 return;
20             }
21             fileTxt = readText(filename);
22             if (fileTxt is null) {
23                 fileTxt = "";
24             }
25         }
26     } else {
27         if (stdin.size != 0) {
28             foreach (line; stdin.byLine()) {
29                 fileTxt ~= line ~ "\n";
30             }
31         }
32     }
33     Clipboard.init();
34
35     Buffer buf = new Buffer(fileTxt, filename);
36     init();
37
38     Cursor cursor = new Cursor();
39     View v = new View(buf, cursor);
40
41     setInputMode(InputMode.mouse);
42
43     Event e;
44     try {
45         while (e.key != Key.ctrlQ) {
46             clear();
47
48             v.display();
49
50             flush();
51             pollEvent(&e);
52
53             v.update(e);
54         }
55     } catch (object.Error e) {
56         shutdown();
57         writeln(e);
58         return;
59     } catch (Exception e) {
60         shutdown();
61         writeln(e);
62         return;
63     }
64
65     shutdown();
66 }