2 * Copyright Neil Brown ©2015-2023 <neil@brown.name>
3 * May be distributed under terms of GPLv2 - see file:COPYING
20 static const char shortopt[] = "gtx";
22 int main(int argc, char *argv[])
25 struct pane *first_window = NULL;
26 struct pane *p, *doc = NULL;
27 bool gtk = False, term = False, x11 = False;
32 base = strrchr(argv[0], '/');
38 ed = editor_new(base);
43 while ((opt = getopt(argc, argv, shortopt)) != EOF) {
47 case 't': term = True;
52 fprintf(stderr, "Usage: edlib [-g] [-t] [file ...]\n");
56 if (!gtk && !term && !x11)
59 setlocale(LC_ALL, "");
60 setlocale(LC_CTYPE, "enUS.UTF-8");
62 call("global-load-module", ed, 0, NULL, "lib-config");
63 call("config-load", ed, 0, NULL, "{COMM}.ini");
65 call("attach-doc-docs", ed);
67 while (optind < argc) {
68 char *file = argv[optind++];
69 int fd = open(file, O_RDONLY);
71 /* '4' says 'allow create' */
72 doc = call_ret(pane, "doc:open", ed, -1, NULL, file, 4);
74 doc = call_ret(pane, "doc:open", ed, fd, NULL, file);
80 char *welcome_file = call_ret(str, "xdg-find-edlib-file", ed,
81 0, NULL, "Welcome-{COMM}.txt",
83 char *WelcomeText = NULL;
85 int fd = open(welcome_file, O_RDONLY);
87 int len = lseek(fd, 0, SEEK_END);
88 lseek(fd, 0, SEEK_SET);
89 if (len > 0 && len < 10000) {
90 WelcomeText = malloc(len+1);
91 read(fd, WelcomeText, len);
100 WelcomeText = strdup("Welcome.\n");
102 doc = call_ret(pane, "doc:from-text", ed, 0, NULL,
103 "*Welcome*", 0, NULL, WelcomeText);
107 fprintf(stderr, "edlib: cannot create default document.\n");
112 char *TERM = getenv("TERM");
114 p = call_ret(pane, "attach-display-ncurses", ed,
115 0, NULL, "-", 0, NULL, TERM);
118 e = getenv("SSH_CONNECTION");
120 call("Window:set:REMOTE_SESSION", p,
123 call("Window:set:DISPLAY", p,
124 0, NULL, getenv("DISPLAY"));
125 call("Window:set:XAUTHORITY", p,
126 0, NULL, getenv("XAUTHORITY"));
129 call("Window:set:no-close", p, 1, NULL,
130 "Cannot close primary display");
131 home_call(p, "Window:activate-display", doc);
136 p = call_ret(pane, "attach-display-gtk",
137 ed, 0, NULL, getenv("DISPLAY"));
138 home_call(p, "Window:activate-display", doc);
144 p = call_ret(pane, "attach-display-x11",
145 ed, 0, NULL, getenv("DISPLAY"),
146 0, NULL, getenv("XAUTHORITY"));
147 home_call(p, "Window:activate-display", doc);
153 call("global-multicall-startup-", first_window);
154 while (call("event:run", ed) == 1)
157 fprintf(stderr, "edlib: cannot create a display\n");