summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/backlog.c226
-rw-r--r--src/bin/backlog.h30
-rw-r--r--src/bin/config.c30
-rw-r--r--src/bin/controls.c2
-rw-r--r--src/bin/ipc.c33
-rw-r--r--src/bin/ipc.h48
-rw-r--r--src/bin/main.c883
-rw-r--r--src/bin/main.h2
-rw-r--r--src/bin/media.c5
-rw-r--r--src/bin/meson.build6
-rw-r--r--src/bin/miniview.c1
-rw-r--r--src/bin/options.c6
-rw-r--r--src/bin/options_behavior.c27
-rw-r--r--src/bin/options_elm.c69
-rw-r--r--src/bin/sb.c13
-rw-r--r--src/bin/termcmd.c18
-rw-r--r--src/bin/termio.c55
-rw-r--r--src/bin/termiointernals.c141
-rw-r--r--src/bin/termiolink.c2
-rw-r--r--src/bin/termpty.c345
-rw-r--r--src/bin/termpty.h20
-rw-r--r--src/bin/termptyesc.c417
-rw-r--r--src/bin/termptyops.c28
-rw-r--r--src/bin/termptysave.c91
-rw-r--r--src/bin/termptysave.h12
-rw-r--r--src/bin/tyalpha.c3
-rw-r--r--src/bin/tybg.c6
-rw-r--r--src/bin/tycat.c12
-rw-r--r--src/bin/tycommon.c24
-rw-r--r--src/bin/tycommon.h1
-rw-r--r--src/bin/tyfuzz.c17
-rw-r--r--src/bin/tyls.c5
-rw-r--r--src/bin/typop.c3
-rw-r--r--src/bin/tyq.c3
-rw-r--r--src/bin/tysend.c12
-rw-r--r--src/bin/utils.c4
-rw-r--r--src/bin/utils.h18
-rw-r--r--src/bin/win.c1072
38 files changed, 2230 insertions, 1460 deletions
diff --git a/src/bin/backlog.c b/src/bin/backlog.c
new file mode 100644
index 0000000..b7271c8
--- /dev/null
+++ b/src/bin/backlog.c
@@ -0,0 +1,226 @@
1#include "private.h"
2#include <Elementary.h>
3#include "termpty.h"
4#include "backlog.h"
5
6
7static int ts_comp = 0;
8static int ts_uncomp = 0;
9static int ts_freeops = 0;
10static Eina_List *ptys = NULL;
11
12static int64_t _mem_used = 0;
13
14static void
15_accounting_change(int64_t diff)
16{
17 if (diff > 0)
18 {
19 diff = ((diff + 16-1) / 16) * 16;
20 }
21 else
22 {
23 diff = ((-1 * diff + 16-1) / 16) * -16;
24 }
25 _mem_used += diff;
26}
27
28int64_t
29termpty_backlog_memory_get(void)
30{
31 return _mem_used;
32}
33
34
35void
36termpty_save_register(Termpty *ty)
37{
38 termpty_backlog_lock();
39 ptys = eina_list_append(ptys, ty);
40 termpty_backlog_unlock();
41}
42
43void
44termpty_save_unregister(Termpty *ty)
45{
46 termpty_backlog_lock();
47 ptys = eina_list_remove(ptys, ty);
48 termpty_backlog_unlock();
49}
50
51Termsave *
52termpty_save_extract(Termsave *ts)
53{
54 if (!ts) return NULL;
55 return ts;
56}
57
58Termsave *
59termpty_save_new(Termpty *ty, Termsave *ts, int w)
60{
61 termpty_save_free(ty, ts);
62
63 Termcell *cells = calloc(1, w * sizeof(Termcell));
64 if (!cells ) return NULL;
65 ts->cells = cells;
66 ts->w = w;
67 _accounting_change(w * sizeof(Termcell));
68 return ts;
69}
70
71Termsave *
72termpty_save_expand(Termpty *ty, Termsave *ts, Termcell *cells, size_t delta)
73{
74 Termcell *newcells;
75
76 newcells = realloc(ts->cells, (ts->w + delta) * sizeof(Termcell));
77 if (!newcells)
78 return NULL;
79
80 memset(newcells + ts->w,
81 0, delta * sizeof(Termcell));
82 TERMPTY_CELL_COPY(ty, cells, &newcells[ts->w], (int)delta);
83
84 _accounting_change(-1 * ts->w * sizeof(Termcell));
85 ts->w += delta;
86 _accounting_change(ts->w * sizeof(Termcell));
87 ts->cells = newcells;
88 return ts;
89}
90
91void
92termpty_save_free(Termpty *ty, Termsave *ts)
93{
94 unsigned int i;
95 if (!ts) return;
96 if (ts->comp) ts_comp--;
97 else ts_uncomp--;
98 ts_freeops++;
99 for (i = 0; i < ts->w; i++)
100 {
101 if (EINA_UNLIKELY(ts->cells[i].att.link_id))
102 term_link_refcount_dec(ty, ts->cells[i].att.link_id, 1);
103 }
104 free(ts->cells);
105 ts->cells = NULL;
106 _accounting_change((-1) * (int)(ts->w * sizeof(Termcell)));
107 ts->w = 0;
108}
109
110void
111termpty_backlog_lock(void)
112{
113}
114
115void
116termpty_backlog_unlock(void)
117{
118}
119
120void
121termpty_backlog_free(Termpty *ty)
122{
123 size_t i;
124
125 if (!ty || !ty->back)
126 return;
127
128 for (i = 0; i < ty->backsize; i++)
129 termpty_save_free(ty, &ty->back[i]);
130 _accounting_change((-1) * (int)(sizeof(Termsave) * ty->backsize));
131 free(ty->back);
132 ty->back = NULL;
133}
134
135void
136termpty_clear_backlog(Termpty *ty)
137{
138 int backsize;
139
140 ty->backlog_beacon.screen_y = 0;
141 ty->backlog_beacon.backlog_y = 0;
142
143 termpty_backlog_lock();
144 termpty_backlog_free(ty);
145 ty->backpos = 0;
146 backsize = ty->backsize;
147 ty->backsize = 0;
148 termpty_backlog_size_set(ty, backsize);
149 termpty_backlog_unlock();
150}
151
152ssize_t
153termpty_backlog_length(Termpty *ty)
154{
155 int backlog_y = ty->backlog_beacon.backlog_y;
156 int screen_y = ty->backlog_beacon.screen_y;
157
158 if (!ty->backsize)
159 return 0;
160
161 for (backlog_y++; backlog_y < (int)ty->backsize; backlog_y++)
162 {
163 int nb_lines;
164 const Termsave *ts;
165
166 ts = BACKLOG_ROW_GET(ty, backlog_y);
167 if (!ts->cells)
168 goto end;
169
170 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
171 screen_y += nb_lines;
172 ty->backlog_beacon.screen_y = screen_y;
173 ty->backlog_beacon.backlog_y = backlog_y;
174 }
175end:
176 return ty->backlog_beacon.screen_y;
177}
178
179
180void
181termpty_backlog_size_set(Termpty *ty, size_t size)
182{
183 Termsave *new_back;
184 size_t i;
185
186 if (ty->backsize == size)
187 return;
188
189 termpty_backlog_lock();
190
191 if (size == 0)
192 {
193 termpty_backlog_free(ty);
194 goto end;
195 }
196 if (size > ty->backsize)
197 {
198 new_back = realloc(ty->back, sizeof(Termsave) * size);
199 if (!new_back)
200 return;
201 memset(new_back + ty->backsize, 0,
202 sizeof(Termsave) * (size - ty->backsize));
203 ty->back = new_back;
204 }
205 else
206 {
207 new_back = calloc(1, sizeof(Termsave) * size);
208 if (!new_back)
209 return;
210 for (i = 0; i < size; i++)
211 new_back[i] = ty->back[i];
212 for (i = size; i < ty->backsize; i++)
213 termpty_save_free(ty, &ty->back[i]);
214 free(ty->back);
215 ty->back = new_back;
216 }
217 _accounting_change(sizeof(Termsave) * (size - ty->backsize));
218end:
219 ty->backpos = 0;
220 ty->backsize = size;
221 /* Reset beacon */
222 ty->backlog_beacon.screen_y = 0;
223 ty->backlog_beacon.backlog_y = 0;
224
225 termpty_backlog_unlock();
226}
diff --git a/src/bin/backlog.h b/src/bin/backlog.h
new file mode 100644
index 0000000..dfe0fd7
--- /dev/null
+++ b/src/bin/backlog.h
@@ -0,0 +1,30 @@
1#ifndef _BACKLOG_H__
2#define _BACKLOG_H__ 1
3
4void termpty_save_register(Termpty *ty);
5void termpty_save_unregister(Termpty *ty);
6Termsave *termpty_save_extract(Termsave *ts);
7Termsave *termpty_save_new(Termpty *ty, Termsave *ts, int w);
8void termpty_save_free(Termpty *ty, Termsave *ts);
9Termsave *termpty_save_expand(Termpty *ty, Termsave *ts,
10 Termcell *cells, size_t delta);
11
12void termpty_backlog_lock(void);
13void termpty_backlog_unlock(void);
14
15void
16termpty_clear_backlog(Termpty *ty);
17void
18termpty_backlog_free(Termpty *ty);
19void
20termpty_backlog_size_set(Termpty *ty, size_t size);
21ssize_t
22termpty_backlog_length(Termpty *ty);
23
24int64_t
25termpty_backlog_memory_get(void);
26
27#define BACKLOG_ROW_GET(Ty, Y) \
28 (&Ty->back[(Ty->backsize + ty->backpos - ((Y) - 1 )) % Ty->backsize])
29
30#endif
diff --git a/src/bin/config.c b/src/bin/config.c
index 52ff2d2..97e10a9 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -216,6 +216,7 @@ config_save(Config *config)
216 char buf[PATH_MAX], buf2[PATH_MAX]; 216 char buf[PATH_MAX], buf2[PATH_MAX];
217 const char *cfgdir; 217 const char *cfgdir;
218 int ok; 218 int ok;
219 Eet_Error err;
219 220
220 EINA_SAFETY_ON_NULL_RETURN(config); 221 EINA_SAFETY_ON_NULL_RETURN(config);
221 222
@@ -236,11 +237,28 @@ config_save(Config *config)
236 snprintf(buf, sizeof(buf), "%s/terminology/config/standard/base.cfg.tmp", cfgdir); 237 snprintf(buf, sizeof(buf), "%s/terminology/config/standard/base.cfg.tmp", cfgdir);
237 snprintf(buf2, sizeof(buf2), "%s/terminology/config/standard/base.cfg", cfgdir); 238 snprintf(buf2, sizeof(buf2), "%s/terminology/config/standard/base.cfg", cfgdir);
238 ef = eet_open(buf, EET_FILE_MODE_WRITE); 239 ef = eet_open(buf, EET_FILE_MODE_WRITE);
239 if (ef) 240 if (!ef)
241 {
242 ERR("error opening file '%s' for writing", buf);
243 return;
244 }
245 ok = eet_data_write(ef, edd_base, CONFIG_KEY, config, 1);
246 if (!ok)
240 { 247 {
241 ok = eet_data_write(ef, edd_base, CONFIG_KEY, config, 1);
242 eet_close(ef); 248 eet_close(ef);
243 if (ok) ecore_file_mv(buf, buf2); 249 ERR("error writing to file '%s'", buf);
250 return;
251 }
252 err = eet_close(ef);
253 if (err != EET_ERROR_NONE)
254 {
255 ERR("error #%d closing file '%s'", err, buf);
256 return;
257 }
258 if (!ecore_file_mv(buf, buf2))
259 {
260 ERR("error moving file '%s' to '%s'", buf, buf2);
261 return;
244 } 262 }
245 main_config_sync(config); 263 main_config_sync(config);
246} 264}
@@ -718,10 +736,12 @@ config_load(void)
718 if (config->version < CONF_VER) 736 if (config->version < CONF_VER)
719 { 737 {
720 // currently no upgrade path so reset config. 738 // currently no upgrade path so reset config.
739 ERR("config is from a newer Terminology, discard it");
721 config_del(config); 740 config_del(config);
722 config = NULL; 741 config = config_new();
742 config->temporary = EINA_TRUE;
723 } 743 }
724 /* do no thing in case the config is from a newer 744 /* do nothing in case the config is from a newer
725 * terminology, we don't want to remove it. */ 745 * terminology, we don't want to remove it. */
726 } 746 }
727 } 747 }
diff --git a/src/bin/controls.c b/src/bin/controls.c
index 279fea3..255eb6b 100644
--- a/src/bin/controls.c
+++ b/src/bin/controls.c
@@ -101,7 +101,7 @@ _cb_ct_new(void *data,
101 void *_event EINA_UNUSED) 101 void *_event EINA_UNUSED)
102{ 102{
103 Controls_Ctx *ctx = data; 103 Controls_Ctx *ctx = data;
104 main_new(ctx->win, ctx->term); 104 main_new(ctx->term);
105} 105}
106 106
107static void 107static void
diff --git a/src/bin/ipc.c b/src/bin/ipc.c
index c9b9ee7..c848e4f 100644
--- a/src/bin/ipc.c
+++ b/src/bin/ipc.c
@@ -1,6 +1,7 @@
1#include "private.h" 1#include "private.h"
2 2
3#include <Ecore.h> 3#include <Ecore.h>
4#include <Ecore_Con.h>
4#include <Ecore_Ipc.h> 5#include <Ecore_Ipc.h>
5#include <Eet.h> 6#include <Eet.h>
6#include "ipc.h" 7#include "ipc.h"
@@ -93,6 +94,8 @@ ipc_init(void)
93 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, 94 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
94 "name", name, EET_T_STRING); 95 "name", name, EET_T_STRING);
95 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, 96 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
97 "theme", theme, EET_T_STRING);
98 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
96 "role", role, EET_T_STRING); 99 "role", role, EET_T_STRING);
97 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, 100 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
98 "title", title, EET_T_STRING); 101 "title", title, EET_T_STRING);
@@ -128,6 +131,16 @@ ipc_init(void)
128 "hold", hold, EET_T_INT); 131 "hold", hold, EET_T_INT);
129 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, 132 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
130 "nowm", nowm, EET_T_INT); 133 "nowm", nowm, EET_T_INT);
134 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
135 "xterm_256color", xterm_256color, EET_T_INT);
136 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
137 "active_links", active_links, EET_T_INT);
138 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
139 "video_mute", active_links, EET_T_INT);
140 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
141 "cursor_blink", active_links, EET_T_INT);
142 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
143 "visual_bell", active_links, EET_T_INT);
131} 144}
132 145
133Eina_Bool 146Eina_Bool
@@ -171,6 +184,19 @@ ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst))
171 func_new_inst = func; 184 func_new_inst = func;
172} 185}
173 186
187void
188ipc_instance_conn_free(void)
189{
190 char *hash = _ipc_hash_get();
191 char *address = ecore_con_local_path_new(EINA_FALSE,
192 hash,
193 0);
194 errno = 0;
195 unlink(address);
196 ERR("unlinking: '%s': %s", address, strerror(errno));
197 free(address);
198}
199
174Eina_Bool 200Eina_Bool
175ipc_instance_add(Ipc_Instance *inst) 201ipc_instance_add(Ipc_Instance *inst)
176{ 202{
@@ -178,7 +204,7 @@ ipc_instance_add(Ipc_Instance *inst)
178 void *data; 204 void *data;
179 char *hash = _ipc_hash_get(); 205 char *hash = _ipc_hash_get();
180 Ecore_Ipc_Server *ipcsrv; 206 Ecore_Ipc_Server *ipcsrv;
181 207
182 if (!hash) return EINA_FALSE; 208 if (!hash) return EINA_FALSE;
183 data = eet_data_descriptor_encode(new_inst_edd, inst, &size); 209 data = eet_data_descriptor_encode(new_inst_edd, inst, &size);
184 if (!data) 210 if (!data)
@@ -186,6 +212,7 @@ ipc_instance_add(Ipc_Instance *inst)
186 free(hash); 212 free(hash);
187 return EINA_FALSE; 213 return EINA_FALSE;
188 } 214 }
215
189 ipcsrv = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, hash, 0, NULL); 216 ipcsrv = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, hash, 0, NULL);
190 if (ipcsrv) 217 if (ipcsrv)
191 { 218 {
@@ -196,6 +223,10 @@ ipc_instance_add(Ipc_Instance *inst)
196 ecore_ipc_server_del(ipcsrv); 223 ecore_ipc_server_del(ipcsrv);
197 return EINA_TRUE; 224 return EINA_TRUE;
198 } 225 }
226 else
227 {
228 DBG("connect failed");
229 }
199 free(data); 230 free(data);
200 free(hash); 231 free(hash);
201 return EINA_FALSE; 232 return EINA_FALSE;
diff --git a/src/bin/ipc.h b/src/bin/ipc.h
index 4ade907..0aa4775 100644
--- a/src/bin/ipc.h
+++ b/src/bin/ipc.h
@@ -7,28 +7,33 @@ typedef struct _Ipc_Instance Ipc_Instance;
7 7
8struct _Ipc_Instance 8struct _Ipc_Instance
9{ 9{
10 const char *cmd; 10 char *cmd;
11 const char *cd; 11 char *cd;
12 const char *background; 12 char *background;
13 const char *name; 13 char *name;
14 const char *role; 14 char *theme;
15 const char *title; 15 char *role;
16 const char *icon_name; 16 char *title;
17 const char *font; 17 char *icon_name;
18 const char *startup_id; 18 char *font;
19 const char *startup_split; 19 char *startup_id;
20 char *startup_split;
20 int x, y, w, h; 21 int x, y, w, h;
21 int pos; 22 Eina_Bool pos;
22 int login_shell; 23 Eina_Bool login_shell;
23 int fullscreen; 24 Eina_Bool fullscreen;
24 int iconic; 25 Eina_Bool iconic;
25 int borderless; 26 Eina_Bool borderless;
26 int override; 27 Eina_Bool override;
27 int maximized; 28 Eina_Bool maximized;
28 int hold; 29 Eina_Bool hold;
29 int nowm; 30 Eina_Bool nowm;
30 int xterm_256color; 31 Eina_Bool xterm_256color;
31 int active_links; 32 Eina_Bool video_mute;
33 Eina_Bool active_links;
34 Eina_Bool cursor_blink;
35 Eina_Bool visual_bell;
36 Config *config;
32}; 37};
33 38
34void ipc_init(void); 39void ipc_init(void);
@@ -36,5 +41,6 @@ void ipc_shutdown(void);
36Eina_Bool ipc_serve(void); 41Eina_Bool ipc_serve(void);
37void ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst)); 42void ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst));
38Eina_Bool ipc_instance_add(Ipc_Instance *inst); 43Eina_Bool ipc_instance_add(Ipc_Instance *inst);
44void ipc_instance_conn_free(void);
39 45
40#endif 46#endif
diff --git a/src/bin/main.c b/src/bin/main.c
index b50dbbe..32e7718 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -27,6 +27,129 @@ Eina_Bool multisense_available = EINA_TRUE;
27static Config *_main_config = NULL; 27static Config *_main_config = NULL;
28 28
29static void 29static void
30_set_instance_theme(Ipc_Instance *inst)
31{
32 char path[PATH_MAX];
33 char theme_name[PATH_MAX];
34 const char *theme_path = (const char *)&path;
35
36 if (!inst->theme)
37 return;
38
39 if (eina_str_has_suffix(inst->theme, ".edj"))
40 eina_strlcpy(theme_name, inst->theme, sizeof(theme_name));
41 else
42 snprintf(theme_name, sizeof(theme_name), "%s.edj", inst->theme);
43
44 if (strchr(theme_name, '/'))
45 eina_strlcpy(path, theme_name, sizeof(path));
46 else
47 theme_path = theme_path_get(theme_name);
48
49 eina_stringshare_replace(&(inst->config->theme), theme_path);
50 inst->config->temporary = EINA_TRUE;
51}
52
53static void
54_configure_instance(Ipc_Instance *inst)
55{
56 Config *config = inst->config;
57
58 _set_instance_theme(inst);
59
60 if (inst->background)
61 {
62 eina_stringshare_replace(&(config->background), inst->background);
63 config->temporary = EINA_TRUE;
64 }
65
66 if (inst->font)
67 {
68 char *p = strchr(inst->font, '/');
69 if (p)
70 {
71 int sz;
72 char *fname = alloca(p - inst->font + 1);
73
74 strncpy(fname, inst->font, p - inst->font);
75 fname[p - inst->font] = '\0';
76 sz = atoi(p+1);
77 if (sz > 0)
78 inst->config->font.size = sz;
79 eina_stringshare_replace(&(inst->config->font.name), fname);
80 inst->config->font.bitmap = EINA_FALSE;
81 }
82 else
83 {
84 char buf[4096], *file;
85 Eina_List *files;
86 int n = strlen(inst->font);
87 Eina_Bool found = EINA_FALSE;
88
89 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
90 files = ecore_file_ls(buf);
91 EINA_LIST_FREE(files, file)
92 {
93 if (n > 0)
94 {
95 if (!strncasecmp(file, inst->font, n))
96 {
97 n = -1;
98 eina_stringshare_replace(&(inst->config->font.name), file);
99 inst->config->font.bitmap = EINA_TRUE;
100 found = EINA_TRUE;
101 }
102 }
103 free(file);
104 }
105 if (!found)
106 {
107 ERR("font '%s' not found in %s", inst->font, buf);
108 }
109 }
110 config->font_set = EINA_TRUE;
111 config->temporary = EINA_TRUE;
112 }
113
114 if (inst->login_shell != 0xff)
115 {
116 inst->config->login_shell = inst->login_shell;
117 inst->config->temporary = EINA_TRUE;
118 }
119 inst->login_shell = inst->config->login_shell;
120
121 if (inst->xterm_256color)
122 {
123 inst->config->xterm_256color = EINA_TRUE;
124 inst->config->temporary = EINA_TRUE;
125 }
126 if (inst->video_mute != 0xff)
127 {
128 config->mute = inst->video_mute;
129 config->temporary = EINA_TRUE;
130 }
131 if (inst->cursor_blink != 0xff)
132 {
133 config->disable_cursor_blink = !inst->cursor_blink;
134 config->temporary = EINA_TRUE;
135 }
136 if (inst->visual_bell != 0xff)
137 {
138 config->disable_visual_bell = !inst->visual_bell;
139 config->temporary = EINA_TRUE;
140 }
141 if (inst->active_links != 0xff)
142 {
143 config->active_links = !!inst->active_links;
144 config->active_links_email = inst->config->active_links;
145 config->active_links_file = inst->config->active_links;
146 config->active_links_url = inst->config->active_links;
147 config->active_links_escape = inst->config->active_links;
148 config->temporary = EINA_TRUE;
149 }
150}
151
152static void
30_check_multisense(void) 153_check_multisense(void)
31{ 154{
32 int enabled; 155 int enabled;
@@ -70,7 +193,7 @@ main_ipc_new(Ipc_Instance *inst)
70 char buf[4096]; 193 char buf[4096];
71 194
72 snprintf(buf, sizeof(buf), "DESKTOP_STARTUP_ID=%s", inst->startup_id); 195 snprintf(buf, sizeof(buf), "DESKTOP_STARTUP_ID=%s", inst->startup_id);
73 putenv(buf); 196 putenv(strdup(buf));
74 } 197 }
75 ecore_app_args_get(&pargc, &pargv); 198 ecore_app_args_get(&pargc, &pargv);
76 nargc = 1; 199 nargc = 1;
@@ -93,7 +216,11 @@ main_ipc_new(Ipc_Instance *inst)
93 if (inst->nowm) nargc += 1; 216 if (inst->nowm) nargc += 1;
94 if (inst->xterm_256color) nargc += 1; 217 if (inst->xterm_256color) nargc += 1;
95 if (inst->active_links) nargc += 1; 218 if (inst->active_links) nargc += 1;
219 if (inst->video_mute) nargc += 1;
220 if (inst->cursor_blink) nargc += 1;
221 if (inst->visual_bell) nargc += 1;
96 if (inst->cmd) nargc += 2; 222 if (inst->cmd) nargc += 2;
223 if (inst->theme) nargc += 2;
97 224
98 nargv = calloc(nargc + 1, sizeof(char *)); 225 nargv = calloc(nargc + 1, sizeof(char *));
99 if (!nargv) return; 226 if (!nargv) return;
@@ -115,6 +242,11 @@ main_ipc_new(Ipc_Instance *inst)
115 nargv[i++] = "-n"; 242 nargv[i++] = "-n";
116 nargv[i++] = (char *)inst->name; 243 nargv[i++] = (char *)inst->name;
117 } 244 }
245 if (inst->theme)
246 {
247 nargv[i++] = "-t";
248 nargv[i++] = (char *)inst->theme;
249 }
118 if (inst->role) 250 if (inst->role)
119 { 251 {
120 nargv[i++] = "-r"; 252 nargv[i++] = "-r";
@@ -232,6 +364,19 @@ main_ipc_new(Ipc_Instance *inst)
232 nargv[i++] = "-e"; 364 nargv[i++] = "-e";
233 nargv[i++] = (char *)inst->cmd; 365 nargv[i++] = (char *)inst->cmd;
234 } 366 }
367 if (inst->video_mute)
368 {
369 nargv[i++] = "-m";
370 }
371 if (inst->cursor_blink)
372 {
373 nargv[i++] = "-c";
374 }
375 if (inst->visual_bell)
376 {
377 nargv[i++] = "-G";
378 }
379
235 380
236 ecore_app_args_set(nargc, (const char **)nargv); 381 ecore_app_args_set(nargc, (const char **)nargv);
237 wn = win_new(inst->name, inst->role, inst->title, inst->icon_name, 382 wn = win_new(inst->name, inst->role, inst->title, inst->icon_name,
@@ -247,60 +392,9 @@ main_ipc_new(Ipc_Instance *inst)
247 392
248 win = win_evas_object_get(wn); 393 win = win_evas_object_get(wn);
249 config = win_config_get(wn); 394 config = win_config_get(wn);
395 inst->config = config;
250 396
251 unsetenv("DESKTOP_STARTUP_ID"); 397 _configure_instance(inst);
252 if (inst->background)
253 {
254 eina_stringshare_replace(&(config->background), inst->background);
255 config->temporary = EINA_TRUE;
256 }
257
258 if (inst->font)
259 {
260 if (strchr(inst->font, '/'))
261 {
262 char *fname = alloca(strlen(inst->font) + 1);
263 char *p;
264
265 strcpy(fname, inst->font);
266 p = strrchr(fname, '/');
267 if (p)
268 {
269 int sz;
270
271 *p = 0;
272 p++;
273 sz = atoi(p);
274 if (sz > 0) config->font.size = sz;
275 eina_stringshare_replace(&(config->font.name), fname);
276 }
277 config->font.bitmap = 0;
278 }
279 else
280 {
281 char buf[4096], *file;
282 Eina_List *files;
283 int n = strlen(inst->font);
284
285 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
286 files = ecore_file_ls(buf);
287 EINA_LIST_FREE(files, file)
288 {
289 if (n > 0)
290 {
291 if (!strncasecmp(file, inst->font, n))
292 {
293 n = -1;
294 eina_stringshare_replace(&(config->font.name), file);
295 config->font.bitmap = 1;
296 }
297 }
298 free(file);
299 }
300 }
301 config->font_set = EINA_TRUE;
302 config->temporary = EINA_TRUE;
303 }
304 398
305 if (inst->w <= 0) inst->w = 80; 399 if (inst->w <= 0) inst->w = 80;
306 if (inst->h <= 0) inst->h = 24; 400 if (inst->h <= 0) inst->h = 24;
@@ -337,6 +431,7 @@ main_ipc_new(Ipc_Instance *inst)
337 (ecore_evas_ecore_evas_get(evas_object_evas_get(win)), 1); 431 (ecore_evas_ecore_evas_get(evas_object_evas_get(win)), 1);
338 ecore_app_args_set(pargc, (const char **)pargv); 432 ecore_app_args_set(pargc, (const char **)pargv);
339 free(nargv); 433 free(nargv);
434 unsetenv("DESKTOP_STARTUP_ID");
340} 435}
341 436
342static const char *emotion_choices[] = { 437static const char *emotion_choices[] = {
@@ -409,6 +504,8 @@ static Ecore_Getopt options = {
409 gettext_noop("Set TERM to 'xterm-256color' instead of 'xterm'.")), 504 gettext_noop("Set TERM to 'xterm-256color' instead of 'xterm'.")),
410 ECORE_GETOPT_STORE_BOOL('\0', "active-links", 505 ECORE_GETOPT_STORE_BOOL('\0', "active-links",
411 gettext_noop("Highlight links.")), 506 gettext_noop("Highlight links.")),
507 ECORE_GETOPT_STORE_BOOL('\0', "no-wizard",
508 gettext_noop("Do not display wizard on start up.")),
412 509
413 ECORE_GETOPT_VERSION ('V', "version"), 510 ECORE_GETOPT_VERSION ('V', "version"),
414 ECORE_GETOPT_COPYRIGHT ('C', "copyright"), 511 ECORE_GETOPT_COPYRIGHT ('C', "copyright"),
@@ -468,65 +565,282 @@ _log_void(const Eina_Log_Domain *_d EINA_UNUSED,
468} 565}
469#endif 566#endif
470 567
568static void
569_start(Ipc_Instance *instance, Eina_Bool need_scale_wizard)
570{
571 Win *wn;
572 Evas_Object *win;
573 Term *term;
574 Config *config;
575
576 wn = win_new(instance->name, instance->role, instance->title,
577 instance->icon_name, instance->config,
578 instance->fullscreen, instance->iconic, instance->borderless,
579 instance->override, instance->maximized);
580 // set an env so terminal apps can detect they are in terminology :)
581 putenv("TERMINOLOGY=1");
582
583 config_del(instance->config);
584 config = NULL;
585 if (!wn)
586 {
587 CRITICAL(_("Could not create window."));
588 goto exit;
589 }
590
591 config = win_config_get(wn);
592
593 term = term_new(wn, config, instance->cmd, instance->login_shell,
594 instance->cd,
595 instance->w, instance->h, instance->hold, instance->title);
596 if (!term)
597 {
598 CRITICAL(_("Could not create terminal widget."));
599 config = NULL;
600 goto exit;
601 }
602
603 if (win_term_set(wn, term) < 0)
604 {
605 goto exit;
606 }
607
608 main_trans_update(config);
609 main_media_update(config);
610 win_sizing_handle(wn);
611 win = win_evas_object_get(wn);
612 evas_object_show(win);
613 if (instance->startup_split)
614 {
615 unsigned int i = 0;
616 Eina_List *cmds_list = NULL;
617 Term *next = term;
618
619 for (i = 0; i < strlen(instance->startup_split); i++)
620 {
621 char *cmd = NULL;
622
623 if (instance->startup_split[i] == 'v')
624 {
625 cmd = cmds_list ? cmds_list->data : NULL;
626 split_vertically(win_evas_object_get(term_win_get(next)),
627 term_termio_get(next), cmd);
628 cmds_list = eina_list_remove_list(cmds_list, cmds_list);
629 }
630 else if (instance->startup_split[i] == 'h')
631 {
632 cmd = cmds_list ? cmds_list->data : NULL;
633 split_horizontally(win_evas_object_get(term_win_get(next)),
634 term_termio_get(next), cmd);
635 cmds_list = eina_list_remove_list(cmds_list, cmds_list);
636 }
637 else if (instance->startup_split[i] == '-')
638 next = term_next_get(next);
639 else
640 {
641 CRITICAL(_("invalid argument found for option -S/--split."
642 " See --help."));
643 goto end;
644 }
645 }
646 if (cmds_list)
647 eina_list_free(cmds_list);
648 }
649 if (instance->pos)
650 {
651 int screen_w, screen_h;
652
653 elm_win_screen_size_get(win, NULL, NULL, &screen_w, &screen_h);
654 if (instance->x < 0) instance->x = screen_w + instance->x;
655 if (instance->y < 0) instance->y = screen_h + instance->y;
656 evas_object_move(win, instance->x, instance->y);
657 }
658 if (instance->nowm)
659 ecore_evas_focus_set(ecore_evas_ecore_evas_get(
660 evas_object_evas_get(win)), 1);
661
662 controls_init();
663
664 if (need_scale_wizard)
665 win_scale_wizard(win, term);
666
667 terminology_starting_up = EINA_FALSE;
668
669
670end:
671 return;
672exit:
673 ecore_main_loop_quit();
674}
675
676struct Instance_Add {
677 Ipc_Instance *instance;
678 char **argv;
679 Eina_Bool result;
680 Eina_Bool timedout;
681 Eina_Bool done;
682 pthread_mutex_t lock;
683};
684
685static void
686_instance_add_free(struct Instance_Add *add)
687{
688 if (!add)
689 return;
690
691 pthread_mutex_destroy(&add->lock);
692 free(add);
693}
694
695
696static void *
697_instance_sleep(void *data)
698{
699 struct Instance_Add *add = data;
700 Eina_Bool timedout = EINA_FALSE;
701
702 sleep(2);
703 pthread_mutex_lock(&add->lock);
704 if (!add->done)
705 timedout = add->timedout = EINA_TRUE;
706 pthread_mutex_unlock(&add->lock);
707 if (timedout)
708 {
709 /* ok, we waited 2 seconds without any answer,
710 * remove the unix socket and restart terminology from scratch in a
711 * better state */
712 ipc_instance_conn_free();
713 errno = 0;
714 execv(add->argv[0], add->argv);
715 ERR("execv failed on '%s': %s", add->argv[0], strerror(errno));
716 }
717 else
718 {
719 _instance_add_free(add);
720 }
721
722 return NULL;
723}
724
725static Eina_Bool
726_instance_add_waiter(Ipc_Instance *instance,
727 char **argv)
728{
729 struct Instance_Add *add;
730 Eina_Bool timedout = EINA_FALSE;
731 Eina_Bool result = EINA_TRUE;
732 pthread_t thr;
733
734 add = calloc(1, sizeof(*add));
735 if (!add)
736 return EINA_FALSE;
737
738 add->instance = instance;
739 add->argv = argv;
740 pthread_mutex_init(&add->lock, NULL);
741
742 pthread_create(&thr, NULL, &_instance_sleep, add);
743
744 /* If the unix socket is stalled, this might block */
745 result = ipc_instance_add(add->instance);
746 pthread_mutex_lock(&add->lock);
747 /* Hoora, it did not block! */
748 add->done = EINA_TRUE;
749 if (add->timedout)
750 {
751 timedout = add->timedout = EINA_TRUE;
752 result = EINA_FALSE;
753 }
754 pthread_mutex_unlock(&add->lock);
755 if (timedout)
756 _instance_add_free(add);
757
758 return result;
759}
760
761static Eina_Bool
762_start_multi(Ipc_Instance *instance,
763 char **argv,
764 Eina_Bool need_scale_wizard)
765{
766 int remote_try = 0;
767 do
768 {
769 if (_instance_add_waiter(instance, argv))
770 {
771 goto exit;
772 }
773 /* Could not start a new window remotely,
774 * let's start our own server */
775 ipc_instance_new_func_set(main_ipc_new);
776 if (ipc_serve())
777 {
778 goto normal_start;
779 }
780 else
781 {
782 DBG("IPC server: failure");
783 }
784 remote_try++;
785 }
786 while (remote_try <= 1);
787
788normal_start:
789 _start(instance, need_scale_wizard);
790 return EINA_FALSE;
791
792exit:
793 return EINA_TRUE;
794}
795
471EAPI_MAIN int 796EAPI_MAIN int
472elm_main(int argc, char **argv) 797elm_main(int argc, char **argv)
473{ 798{
474 char *cmd = NULL;
475 char *cd = NULL;
476 char *theme = NULL;
477 char *background = NULL;
478 char *geometry = NULL; 799 char *geometry = NULL;
479 char *name = NULL;
480 char *role = NULL;
481 char *title = NULL;
482 char *icon_name = NULL;
483 char *font = NULL;
484 char *startup_split = NULL;
485 char *video_module = NULL; 800 char *video_module = NULL;
486 Eina_Bool login_shell = 0xff; /* unset */
487 Eina_Bool video_mute = 0xff; /* unset */
488 Eina_Bool cursor_blink = 0xff; /* unset */
489 Eina_Bool visual_bell = 0xff; /* unset */
490 Eina_Bool active_links = 0xff; /* unset */
491 Eina_Bool fullscreen = EINA_FALSE;
492 Eina_Bool iconic = EINA_FALSE;
493 Eina_Bool borderless = EINA_FALSE;
494 Eina_Bool override = EINA_FALSE;
495 Eina_Bool maximized = EINA_FALSE;
496 Eina_Bool nowm = EINA_FALSE;
497 Eina_Bool quit_option = EINA_FALSE; 801 Eina_Bool quit_option = EINA_FALSE;
498 Eina_Bool hold = EINA_FALSE;
499 Eina_Bool single = EINA_FALSE; 802 Eina_Bool single = EINA_FALSE;
803 Eina_Bool no_wizard = EINA_FALSE;
500 Eina_Bool cmd_options = EINA_FALSE; 804 Eina_Bool cmd_options = EINA_FALSE;
501 Eina_Bool xterm_256color = EINA_FALSE; 805 Ipc_Instance instance = {
806 .login_shell = 0xff, /* unset */
807 .active_links = 0xff, /* unset */
808 .video_mute = 0xff, /* unset */
809 .cursor_blink = 0xff, /* unset */
810 .visual_bell = 0xff, /* unset */
811 .startup_id = getenv("DESKTOP_STARTUP_ID"),
812 .w = 1,
813 .h = 1,
814 };
502 Ecore_Getopt_Value values[] = { 815 Ecore_Getopt_Value values[] = {
503 ECORE_GETOPT_VALUE_BOOL(cmd_options), 816 ECORE_GETOPT_VALUE_BOOL(cmd_options),
504 ECORE_GETOPT_VALUE_STR(cd), 817 ECORE_GETOPT_VALUE_STR(instance.cd),
505 ECORE_GETOPT_VALUE_STR(theme), 818 ECORE_GETOPT_VALUE_STR(instance.theme),
506 ECORE_GETOPT_VALUE_STR(background), 819 ECORE_GETOPT_VALUE_STR(instance.background),
507 ECORE_GETOPT_VALUE_STR(geometry), 820 ECORE_GETOPT_VALUE_STR(geometry),
508 ECORE_GETOPT_VALUE_STR(name), 821 ECORE_GETOPT_VALUE_STR(instance.name),
509 ECORE_GETOPT_VALUE_STR(role), 822 ECORE_GETOPT_VALUE_STR(instance.role),
510 ECORE_GETOPT_VALUE_STR(title), 823 ECORE_GETOPT_VALUE_STR(instance.title),
511 ECORE_GETOPT_VALUE_STR(icon_name), 824 ECORE_GETOPT_VALUE_STR(instance.icon_name),
512 ECORE_GETOPT_VALUE_STR(font), 825 ECORE_GETOPT_VALUE_STR(instance.font),
513 ECORE_GETOPT_VALUE_STR(startup_split), 826 ECORE_GETOPT_VALUE_STR(instance.startup_split),
514 ECORE_GETOPT_VALUE_STR(video_module), 827 ECORE_GETOPT_VALUE_STR(video_module),
515 828
516 ECORE_GETOPT_VALUE_BOOL(login_shell), 829 ECORE_GETOPT_VALUE_BOOL(instance.login_shell),
517 ECORE_GETOPT_VALUE_BOOL(video_mute), 830 ECORE_GETOPT_VALUE_BOOL(instance.video_mute),
518 ECORE_GETOPT_VALUE_BOOL(cursor_blink), 831 ECORE_GETOPT_VALUE_BOOL(instance.cursor_blink),
519 ECORE_GETOPT_VALUE_BOOL(visual_bell), 832 ECORE_GETOPT_VALUE_BOOL(instance.visual_bell),
520 ECORE_GETOPT_VALUE_BOOL(fullscreen), 833 ECORE_GETOPT_VALUE_BOOL(instance.fullscreen),
521 ECORE_GETOPT_VALUE_BOOL(iconic), 834 ECORE_GETOPT_VALUE_BOOL(instance.iconic),
522 ECORE_GETOPT_VALUE_BOOL(borderless), 835 ECORE_GETOPT_VALUE_BOOL(instance.borderless),
523 ECORE_GETOPT_VALUE_BOOL(override), 836 ECORE_GETOPT_VALUE_BOOL(instance.override),
524 ECORE_GETOPT_VALUE_BOOL(maximized), 837 ECORE_GETOPT_VALUE_BOOL(instance.maximized),
525 ECORE_GETOPT_VALUE_BOOL(nowm), 838 ECORE_GETOPT_VALUE_BOOL(instance.nowm),
526 ECORE_GETOPT_VALUE_BOOL(hold), 839 ECORE_GETOPT_VALUE_BOOL(instance.hold),
527 ECORE_GETOPT_VALUE_BOOL(single), 840 ECORE_GETOPT_VALUE_BOOL(single),
528 ECORE_GETOPT_VALUE_BOOL(xterm_256color), 841 ECORE_GETOPT_VALUE_BOOL(instance.xterm_256color),
529 ECORE_GETOPT_VALUE_BOOL(active_links), 842 ECORE_GETOPT_VALUE_BOOL(instance.active_links),
843 ECORE_GETOPT_VALUE_BOOL(no_wizard),
530 844
531 ECORE_GETOPT_VALUE_BOOL(quit_option), 845 ECORE_GETOPT_VALUE_BOOL(quit_option),
532 ECORE_GETOPT_VALUE_BOOL(quit_option), 846 ECORE_GETOPT_VALUE_BOOL(quit_option),
@@ -535,16 +849,9 @@ elm_main(int argc, char **argv)
535 849
536 ECORE_GETOPT_VALUE_NONE 850 ECORE_GETOPT_VALUE_NONE
537 }; 851 };
538 Win *wn;
539 Term *term;
540 Config *config = NULL;
541 Evas_Object *win;
542 int args, retval = EXIT_SUCCESS; 852 int args, retval = EXIT_SUCCESS;
543 int remote_try = 0; 853 Eina_Bool size_set = EINA_FALSE;
544 int pos_set = 0, size_set = 0; 854 Eina_Bool need_scale_wizard = utils_need_scale_wizard();
545 int pos_x = 0, pos_y = 0;
546 int size_w = 1, size_h = 1;
547 Eina_List *cmds_list = NULL;
548 855
549 terminology_starting_up = EINA_TRUE; 856 terminology_starting_up = EINA_TRUE;
550 857
@@ -590,9 +897,12 @@ elm_main(int argc, char **argv)
590 goto end; 897 goto end;
591 } 898 }
592 899
900 ecore_con_init();
901 ecore_con_url_init();
902
593 ipc_init(); 903 ipc_init();
594 904
595 config = config_fork(_main_config); 905 instance.config = config_fork(_main_config);
596 906
597 args = ecore_getopt_parse(&options, values, argc, argv); 907 args = ecore_getopt_parse(&options, values, argc, argv);
598 if (args < 0) 908 if (args < 0)
@@ -602,10 +912,15 @@ elm_main(int argc, char **argv)
602 goto end; 912 goto end;
603 } 913 }
604 914
605 if (quit_option) goto end; 915 if (no_wizard)
916 need_scale_wizard = EINA_FALSE;
917
918 if (quit_option)
919 goto end;
606 920
607 if (cmd_options) 921 if (cmd_options)
608 { 922 {
923 Eina_List *cmds_list = NULL;
609 int i; 924 int i;
610 925
611 if (args == argc) 926 if (args == argc)
@@ -615,11 +930,11 @@ elm_main(int argc, char **argv)
615 goto end; 930 goto end;
616 } 931 }
617 932
618 if (startup_split) 933 if (instance.startup_split)
619 { 934 {
620 for(i = args+1; i < argc; i++) 935 for(i = args+1; i < argc; i++)
621 cmds_list = eina_list_append(cmds_list, argv[i]); 936 cmds_list = eina_list_append(cmds_list, argv[i]);
622 cmd = argv[args]; 937 instance.cmd = argv[args];
623 } 938 }
624 else 939 else
625 { 940 {
@@ -631,86 +946,15 @@ elm_main(int argc, char **argv)
631 eina_strbuf_append_char(strb, ' '); 946 eina_strbuf_append_char(strb, ' ');
632 eina_strbuf_append(strb, argv[i]); 947 eina_strbuf_append(strb, argv[i]);
633 } 948 }
634 cmd = eina_strbuf_string_steal(strb); 949 instance.cmd = eina_strbuf_string_steal(strb);
635 eina_strbuf_free(strb); 950 eina_strbuf_free(strb);
636 } 951 }
637 } 952 }
638 953
639 _check_multisense(); 954 _check_multisense();
640 955
641 if (theme) 956 _configure_instance(&instance);
642 {
643 char path[PATH_MAX];
644 char theme_name[PATH_MAX];
645 const char *theme_path = (const char *)&path;
646 957
647 if (eina_str_has_suffix(theme, ".edj"))
648 eina_strlcpy(theme_name, theme, sizeof(theme_name));
649 else
650 snprintf(theme_name, sizeof(theme_name), "%s.edj", theme);
651
652 if (strchr(theme_name, '/'))
653 eina_strlcpy(path, theme_name, sizeof(path));
654 else
655 theme_path = theme_path_get(theme_name);
656
657 eina_stringshare_replace(&(config->theme), theme_path);
658 config->temporary = EINA_TRUE;
659 }
660
661 if (background)
662 {
663 eina_stringshare_replace(&(config->background), background);
664 config->temporary = EINA_TRUE;
665 }
666
667 if (font)
668 {
669 char *p = strchr(font, '/');
670 if (p)
671 {
672 int sz;
673 char *fname = alloca(p - font + 1);
674
675 strncpy(fname, font, p - font);
676 fname[p - font] = '\0';
677 sz = atoi(p+1);
678 if (sz > 0) config->font.size = sz;
679 eina_stringshare_replace(&(config->font.name), fname);
680 config->font.bitmap = 0;
681 config->font_set = 1;
682 }
683 else
684 {
685 char buf[4096], *file;
686 Eina_List *files;
687 int n = strlen(font);
688 Eina_Bool found = EINA_FALSE;
689
690 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
691 files = ecore_file_ls(buf);
692 EINA_LIST_FREE(files, file)
693 {
694 if (n > 0)
695 {
696 if (!strncasecmp(file, font, n))
697 {
698 n = -1;
699 eina_stringshare_replace(&(config->font.name), file);
700 config->font.bitmap = 1;
701 config->font_set = 1;
702 found = EINA_TRUE;
703 }
704 }
705 free(file);
706 }
707 if (!found)
708 {
709 ERR("font '%s' not found in %s", font, buf);
710 }
711 }
712 config->temporary = EINA_TRUE;
713 }
714 958
715 if (video_module) 959 if (video_module)
716 { 960 {
@@ -723,270 +967,109 @@ elm_main(int argc, char **argv)
723 967
724 if (i == EINA_C_ARRAY_LENGTH(emotion_choices)) 968 if (i == EINA_C_ARRAY_LENGTH(emotion_choices))
725 i = 0; /* ecore getopt shouldn't let this happen, but... */ 969 i = 0; /* ecore getopt shouldn't let this happen, but... */
726 config->vidmod = i; 970 instance.config->vidmod = i;
727 config->temporary = EINA_TRUE; 971 instance.config->temporary = EINA_TRUE;
728 }
729
730 if (video_mute != 0xff)
731 {
732 config->mute = video_mute;
733 config->temporary = EINA_TRUE;
734 }
735 if (cursor_blink != 0xff)
736 {
737 config->disable_cursor_blink = !cursor_blink;
738 config->temporary = EINA_TRUE;
739 }
740 if (visual_bell != 0xff)
741 {
742 config->disable_visual_bell = !visual_bell;
743 config->temporary = EINA_TRUE;
744 }
745 if (active_links != 0xff)
746 {
747 config->active_links = !!active_links;
748 config->active_links_email = config->active_links;
749 config->active_links_file = config->active_links;
750 config->active_links_url = config->active_links;
751 config->active_links_escape = config->active_links;
752 config->temporary = EINA_TRUE;
753 } 972 }
754 973
755 if (xterm_256color)
756 {
757 config->xterm_256color = EINA_TRUE;
758 config->temporary = EINA_TRUE;
759 }
760 974
761 if (geometry) 975 if (geometry)
762 { 976 {
763 if (sscanf(geometry,"%ix%i+%i+%i", &size_w, &size_h, &pos_x, &pos_y) == 4) 977 if (sscanf(geometry,"%ix%i+%i+%i", &instance.w, &instance.h,
978 &instance.x, &instance.y) == 4)
764 { 979 {
765 pos_set = 1; 980 instance.pos = EINA_TRUE;
766 size_set = 1; 981 size_set = EINA_TRUE;
767 } 982 }
768 else if (sscanf(geometry,"%ix%i-%i+%i", &size_w, &size_h, &pos_x, &pos_y) == 4) 983 else if (sscanf(geometry,"%ix%i-%i+%i", &instance.w, &instance.h,
984 &instance.x, &instance.y) == 4)
769 { 985 {
770 pos_x = -pos_x; 986 instance.x = -instance.x;
771 pos_set = 1; 987 instance.pos = EINA_TRUE;
772 size_set = 1; 988 size_set = EINA_TRUE;
773 } 989 }
774 else if (sscanf(geometry,"%ix%i-%i-%i", &size_w, &size_h, &pos_x, &pos_y) == 4) 990 else if (sscanf(geometry,"%ix%i-%i-%i", &instance.w, &instance.h,
991 &instance.x, &instance.y) == 4)
775 { 992 {
776 pos_x = -pos_x; 993 instance.x = -instance.x;
777 pos_y = -pos_y; 994 instance.y = -instance.y;
778 pos_set = 1; 995 instance.pos = EINA_TRUE;
779 size_set = 1; 996 size_set = EINA_TRUE;
780 } 997 }
781 else if (sscanf(geometry,"%ix%i+%i-%i", &size_w, &size_h, &pos_x, &pos_y) == 4) 998 else if (sscanf(geometry,"%ix%i+%i-%i", &instance.w, &instance.h,
999 &instance.x, &instance.y) == 4)
782 { 1000 {
783 pos_y = -pos_y; 1001 instance.y = -instance.y;
784 pos_set = 1; 1002 instance.pos = EINA_TRUE;
785 size_set = 1; 1003 size_set = EINA_TRUE;
786 } 1004 }
787 else if (sscanf(geometry,"%ix%i", &size_w, &size_h) == 2) 1005 else if (sscanf(geometry,"%ix%i", &instance.w, &instance.h) == 2)
788 { 1006 {
789 size_set = 1; 1007 size_set = EINA_TRUE;
790 } 1008 }
791 else if (sscanf(geometry,"+%i+%i", &pos_x, &pos_y) == 2) 1009 else if (sscanf(geometry,"+%i+%i", &instance.x, &instance.y) == 2)
792 { 1010 {
793 pos_set = 1; 1011 instance.pos = EINA_TRUE;
794 } 1012 }
795 else if (sscanf(geometry,"-%i+%i", &pos_x, &pos_y) == 2) 1013 else if (sscanf(geometry,"-%i+%i", &instance.x, &instance.y) == 2)
796 { 1014 {
797 pos_x = -pos_x; 1015 instance.x = -instance.x;
798 pos_set = 1; 1016 instance.pos = EINA_TRUE;
799 } 1017 }
800 else if (sscanf(geometry,"+%i-%i", &pos_x, &pos_y) == 2) 1018 else if (sscanf(geometry,"+%i-%i", &instance.x, &instance.y) == 2)
801 { 1019 {
802 pos_y = -pos_y; 1020 instance.y = -instance.y;
803 pos_set = 1; 1021 instance.pos = EINA_TRUE;
804 } 1022 }
805 else if (sscanf(geometry,"-%i-%i", &pos_x, &pos_y) == 2) 1023 else if (sscanf(geometry,"-%i-%i", &instance.x, &instance.y) == 2)
806 { 1024 {
807 pos_x = -pos_x; 1025 instance.x = -instance.x;
808 pos_y = -pos_y; 1026 instance.y = -instance.y;
809 pos_set = 1; 1027 instance.pos = EINA_TRUE;
810 } 1028 }
811 } 1029 }
812 1030
813 if (!size_set) 1031 if (!size_set)
814 { 1032 {
815 if (config->custom_geometry) 1033 if (instance.config->custom_geometry)
816 { 1034 {
817 size_w = config->cg_width; 1035 instance.w = instance.config->cg_width;
818 size_h = config->cg_height; 1036 instance.h = instance.config->cg_height;
819 } 1037 }
820 else 1038 else
821 { 1039 {
822 size_w = 80; 1040 instance.w = 80;
823 size_h = 24; 1041 instance.h = 24;
824 } 1042 }
825 } 1043 }
826 1044
827 if (login_shell != 0xff) 1045 elm_theme_overlay_add(NULL,
828 { 1046 config_theme_path_default_get(instance.config));
829 config->login_shell = login_shell; 1047 elm_theme_overlay_add(NULL, config_theme_path_get(instance.config));
830 config->temporary = EINA_TRUE;
831 }
832 login_shell = config->login_shell;
833 1048
834 elm_theme_overlay_add(NULL, config_theme_path_default_get(config)); 1049 if ((!single) && (instance.config->multi_instance))
835 elm_theme_overlay_add(NULL, config_theme_path_get(config));
836
837remote:
838 if ((!single) && (config->multi_instance))
839 { 1050 {
840 Ipc_Instance inst;
841 char cwdbuf[4096]; 1051 char cwdbuf[4096];
842 1052
843 memset(&inst, 0, sizeof(Ipc_Instance)); 1053 if (!instance.cd)
844 1054 instance.cd = getcwd(cwdbuf, sizeof(cwdbuf));
845 inst.cmd = cmd; 1055 if (_start_multi(&instance, argv, need_scale_wizard))
846 if (cd) inst.cd = cd;
847 else inst.cd = getcwd(cwdbuf, sizeof(cwdbuf));
848 inst.background = background;
849 inst.name = name;
850 inst.role = role;
851 inst.title = title;
852 inst.icon_name = icon_name;
853 inst.font = font;
854 inst.startup_id = getenv("DESKTOP_STARTUP_ID");
855 inst.x = pos_x;
856 inst.y = pos_y;
857 inst.w = size_w;
858 inst.h = size_h;
859 inst.pos = pos_set;
860 inst.login_shell = login_shell;
861 inst.fullscreen = fullscreen;
862 inst.iconic = iconic;
863 inst.borderless = borderless;
864 inst.override = override;
865 inst.maximized = maximized;
866 inst.hold = hold;
867 inst.nowm = nowm;
868 inst.startup_split = startup_split;
869 if (ipc_instance_add(&inst))
870 goto end; 1056 goto end;
871 } 1057 }
872 if ((!single) && (config->multi_instance)) 1058 else
873 {
874 ipc_instance_new_func_set(main_ipc_new);
875 if (!ipc_serve())
876 {
877 if (remote_try < 1)
878 {
879 remote_try++;
880 goto remote;
881 }
882 }
883 }
884
885 wn = win_new(name, role, title, icon_name, config,
886 fullscreen, iconic, borderless, override, maximized);
887 // set an env so terminal apps can detect they are in terminology :)
888 putenv("TERMINOLOGY=1");
889 unsetenv("DESKTOP_STARTUP_ID");
890
891 config_del(config);
892 config = NULL;
893 if (!wn)
894 {
895 CRITICAL(_("Could not create window."));
896 retval = EXIT_FAILURE;
897 goto end;
898 }
899
900 config = win_config_get(wn);
901
902 term = term_new(wn, config, cmd, login_shell, cd,
903 size_w, size_h, hold, title);
904 if (!term)
905 { 1059 {
906 CRITICAL(_("Could not create terminal widget.")); 1060 _start(&instance, need_scale_wizard);
907 config = NULL;
908 retval = EXIT_FAILURE;
909 goto end;
910 }
911
912 if (win_term_set(wn, term) < 0)
913 {
914 retval = EXIT_FAILURE;
915 goto end;
916 } 1061 }
917
918 main_trans_update(config);
919 main_media_update(config);
920 win_sizing_handle(wn);
921 win = win_evas_object_get(wn);
922 evas_object_show(win);
923 if (startup_split)
924 {
925 unsigned int i = 0;
926 Term *next = term;
927
928 for (i = 0; i < strlen(startup_split); i++)
929 {
930 if (startup_split[i] == 'v')
931 {
932 cmd = cmds_list ? cmds_list->data : NULL;
933 split_vertically(win_evas_object_get(term_win_get(next)),
934 term_termio_get(next), cmd);
935 cmds_list = eina_list_remove_list(cmds_list, cmds_list);
936 }
937 else if (startup_split[i] == 'h')
938 {
939 cmd = cmds_list ? cmds_list->data : NULL;
940 split_horizontally(win_evas_object_get(term_win_get(next)),
941 term_termio_get(next), cmd);
942 cmds_list = eina_list_remove_list(cmds_list, cmds_list);
943 }
944 else if (startup_split[i] == '-')
945 next = term_next_get(next);
946 else
947 {
948 CRITICAL(_("invalid argument found for option -S/--split."
949 " See --help."));
950 goto end;
951 }
952 }
953 if (cmds_list)
954 eina_list_free(cmds_list);
955 }
956 if (pos_set)
957 {
958 int screen_w, screen_h;
959
960 elm_win_screen_size_get(win, NULL, NULL, &screen_w, &screen_h);
961 if (pos_x < 0) pos_x = screen_w + pos_x;
962 if (pos_y < 0) pos_y = screen_h + pos_y;
963 evas_object_move(win, pos_x, pos_y);
964 }
965 if (nowm)
966 ecore_evas_focus_set(ecore_evas_ecore_evas_get(
967 evas_object_evas_get(win)), 1);
968
969 ecore_con_init();
970 ecore_con_url_init();
971
972 controls_init();
973
974 win_scale_wizard(win, term);
975
976 terminology_starting_up = EINA_FALSE;
977
978 elm_run(); 1062 elm_run();
979 1063
980 ecore_con_url_shutdown(); 1064 ecore_con_url_shutdown();
981 ecore_con_shutdown(); 1065 ecore_con_shutdown();
982 1066
983 config = NULL; 1067 instance.config = NULL;
984 end: 1068 end:
985 if (!startup_split) free(cmd); 1069 if (instance.config)
986 if (config)
987 { 1070 {
988 config_del(config); 1071 config_del(instance.config);
989 config = NULL; 1072 instance.config = NULL;
990 } 1073 }
991 1074
992 ipc_shutdown(); 1075 ipc_shutdown();
diff --git a/src/bin/main.h b/src/bin/main.h
index 1a961d4..e870b32 100644
--- a/src/bin/main.h
+++ b/src/bin/main.h
@@ -4,7 +4,7 @@
4#include "config.h" 4#include "config.h"
5 5
6Config * main_config_get(void); 6Config * main_config_get(void);
7void main_new(Evas_Object *win, Evas_Object *term); 7void main_new(Evas_Object *term);
8void main_new_with_dir(Evas_Object *win, Evas_Object *term, const char *wdir); 8void main_new_with_dir(Evas_Object *win, Evas_Object *term, const char *wdir);
9void main_split_h(Evas_Object *win, Evas_Object *term, const char *cmd); 9void main_split_h(Evas_Object *win, Evas_Object *term, const char *cmd);
10void main_split_v(Evas_Object *win, Evas_Object *term, const char *cmd); 10void main_split_v(Evas_Object *win, Evas_Object *term, const char *cmd);
diff --git a/src/bin/media.c b/src/bin/media.c
index b43eadc..6240445 100644
--- a/src/bin/media.c
+++ b/src/bin/media.c
@@ -964,8 +964,8 @@ _smart_del(Evas_Object *obj)
964 if (sd->realf) unlink(sd->realf); 964 if (sd->realf) unlink(sd->realf);
965 close(sd->tmpfd); 965 close(sd->tmpfd);
966 } 966 }
967 if (sd->src) eina_stringshare_del(sd->src); 967 eina_stringshare_del(sd->src);
968 if (sd->realf) eina_stringshare_del(sd->realf); 968 eina_stringshare_del(sd->realf);
969 if (sd->clip) evas_object_del(sd->clip); 969 if (sd->clip) evas_object_del(sd->clip);
970 if (sd->o_img) evas_object_del(sd->o_img); 970 if (sd->o_img) evas_object_del(sd->o_img);
971 if (sd->o_tmp) evas_object_del(sd->o_tmp); 971 if (sd->o_tmp) evas_object_del(sd->o_tmp);
@@ -1248,7 +1248,6 @@ media_add(Evas_Object *parent, const char *src, const Config *config, int mode,
1248 if (!_smart) _smart_init(); 1248 if (!_smart) _smart_init();
1249 obj = evas_object_smart_add(e, _smart); 1249 obj = evas_object_smart_add(e, _smart);
1250 sd = evas_object_smart_data_get(obj); 1250 sd = evas_object_smart_data_get(obj);
1251 if (!sd) return obj;
1252 1251
1253 sd->src = eina_stringshare_add(src); 1252 sd->src = eina_stringshare_add(src);
1254 sd->config = config; 1253 sd->config = config;
diff --git a/src/bin/meson.build b/src/bin/meson.build
index dc6c2a7..6de1d17 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -31,7 +31,7 @@ terminology_sources = ['private.h',
31 'termptyops.c', 'termptyops.h', 31 'termptyops.c', 'termptyops.h',
32 'termptygfx.c', 'termptygfx.h', 32 'termptygfx.c', 'termptygfx.h',
33 'termptyext.c', 'termptyext.h', 33 'termptyext.c', 'termptyext.h',
34 'termptysave.c', 'termptysave.h', 34 'backlog.c', 'backlog.h',
35 'md5/md5.c', 'md5/md5.h', 35 'md5/md5.c', 'md5/md5.h',
36 'utf8.c', 'utf8.h', 36 'utf8.c', 'utf8.h',
37 'win.c', 'win.h', 37 'win.c', 'win.h',
@@ -49,7 +49,7 @@ tycat_sources = ['tycommon.c', 'tycommon.h', 'tycat.c', 'extns.c', 'extns.h']
49tyls_sources = ['extns.c', 'extns.h', 'tyls.c', 'tycommon.c', 'tycommon.h'] 49tyls_sources = ['extns.c', 'extns.h', 'tyls.c', 'tycommon.c', 'tycommon.h']
50tysend_sources = ['tycommon.c', 'tycommon.h', 'tysend.c'] 50tysend_sources = ['tycommon.c', 'tycommon.h', 'tysend.c']
51tyfuzz_sources = ['termptyesc.c', 'termptyesc.h', 51tyfuzz_sources = ['termptyesc.c', 'termptyesc.h',
52 'termptysave.c', 'termptysave.h', 52 'backlog.c', 'backlog.h',
53 'termptyops.c', 'termptyops.h', 53 'termptyops.c', 'termptyops.h',
54 'termptydbl.c', 'termptydbl.h', 54 'termptydbl.c', 'termptydbl.h',
55 'termptyext.c', 'termptyext.h', 55 'termptyext.c', 'termptyext.h',
@@ -64,7 +64,7 @@ tyfuzz_sources = ['termptyesc.c', 'termptyesc.h',
64 'utils.c', 'utils.h', 64 'utils.c', 'utils.h',
65 'tyfuzz.c'] 65 'tyfuzz.c']
66tytest_sources = ['termptyesc.c', 'termptyesc.h', 66tytest_sources = ['termptyesc.c', 'termptyesc.h',
67 'termptysave.c', 'termptysave.h', 67 'backlog.c', 'backlog.h',
68 'termptyops.c', 'termptyops.h', 68 'termptyops.c', 'termptyops.h',
69 'termptydbl.c', 'termptydbl.h', 69 'termptydbl.c', 'termptydbl.h',
70 'termptyext.c', 'termptyext.h', 70 'termptyext.c', 'termptyext.h',
diff --git a/src/bin/miniview.c b/src/bin/miniview.c
index 6149183..8eb7d55 100644
--- a/src/bin/miniview.c
+++ b/src/bin/miniview.c
@@ -12,6 +12,7 @@
12#include "miniview.h" 12#include "miniview.h"
13#include "utils.h" 13#include "utils.h"
14#include "main.h" 14#include "main.h"
15#include "backlog.h"
15 16
16/* specific log domain to help debug only miniview */ 17/* specific log domain to help debug only miniview */
17int _miniview_log_dom = -1; 18int _miniview_log_dom = -1;
diff --git a/src/bin/options.c b/src/bin/options.c
index 4ca0cb1..fec118c 100644
--- a/src/bin/options.c
+++ b/src/bin/options.c
@@ -207,11 +207,11 @@ options_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, Evas_Object *
207 evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL); 207 evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL);
208 elm_toolbar_horizontal_set(o, EINA_FALSE); 208 elm_toolbar_horizontal_set(o, EINA_FALSE);
209 elm_object_style_set(o, "item_horizontal"); 209 elm_object_style_set(o, "item_horizontal");
210 elm_toolbar_icon_size_set(o, 16 * elm_config_scale_get()); 210 elm_toolbar_icon_size_set(o, 24 * elm_config_scale_get());
211 elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL); 211 elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL);
212 elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS); 212 elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS);
213 elm_toolbar_menu_parent_set(o, win); 213 elm_toolbar_menu_parent_set(o, win);
214 elm_toolbar_homogeneous_set(o, EINA_FALSE); 214 elm_toolbar_homogeneous_set(o, EINA_TRUE);
215 215
216#define ITEM_APPEND(_icon_name, _name, _option_mode) \ 216#define ITEM_APPEND(_icon_name, _name, _option_mode) \
217 elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \ 217 elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \
@@ -220,7 +220,7 @@ options_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, Evas_Object *
220 it_fn = ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR); 220 it_fn = ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR);
221 ITEM_APPEND("preferences-desktop-font", _("Font"), FONT); 221 ITEM_APPEND("preferences-desktop-font", _("Font"), FONT);
222 ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME); 222 ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME);
223 ITEM_APPEND("preferences-desktop-background", _("Background"), BACKGROUND); 223 ITEM_APPEND("background", _("Background"), BACKGROUND);
224 ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS); 224 ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS);
225 ITEM_APPEND("video-display", _("Video"), VIDEO); 225 ITEM_APPEND("video-display", _("Video"), VIDEO);
226 ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS); 226 ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS);
diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c
index 1fc4e4a..c945d5d 100644
--- a/src/bin/options_behavior.c
+++ b/src/bin/options_behavior.c
@@ -4,6 +4,8 @@
4#include <math.h> 4#include <math.h>
5#include <Elementary.h> 5#include <Elementary.h>
6#include <assert.h> 6#include <assert.h>
7#include "termpty.h"
8#include "backlog.h"
7#include "config.h" 9#include "config.h"
8#include "termio.h" 10#include "termio.h"
9#include "options.h" 11#include "options.h"
@@ -17,6 +19,8 @@ typedef struct _Behavior_Ctx {
17 Evas_Object *op_wh_current; 19 Evas_Object *op_wh_current;
18 Evas_Object *term; 20 Evas_Object *term;
19 Evas_Object *sld_hide_cursor; 21 Evas_Object *sld_hide_cursor;
22 Evas_Object *backlock_label;
23 char *backlog_msg;
20 Config *config; 24 Config *config;
21} Behavior_Ctx; 25} Behavior_Ctx;
22 26
@@ -86,6 +90,24 @@ sback_units_format(double d)
86} 90}
87 91
88static void 92static void
93_update_backlog_title(Behavior_Ctx *ctx)
94{
95 char *factor = " KMG";
96 double amount = termpty_backlog_memory_get();
97
98 while (amount > 1024.0 && factor[1] != '\0')
99 {
100 amount /= 1024;
101 factor++;
102 }
103 eina_stringshare_del(ctx->backlog_msg);
104 ctx->backlog_msg = (char*) eina_stringshare_printf(
105 _("Scrollback (current memory usage: %'.2f%cB):"),
106 amount, factor[0]);
107 elm_object_text_set(ctx->backlock_label, ctx->backlog_msg);
108}
109
110static void
89_cb_op_behavior_sback_chg(void *data, 111_cb_op_behavior_sback_chg(void *data,
90 Evas_Object *obj, 112 Evas_Object *obj,
91 void *_event EINA_UNUSED) 113 void *_event EINA_UNUSED)
@@ -95,6 +117,7 @@ _cb_op_behavior_sback_chg(void *data,
95 117
96 config->scrollback = (double) sback_double_to_expo_int(elm_slider_value_get(obj)); 118 config->scrollback = (double) sback_double_to_expo_int(elm_slider_value_get(obj));
97 termio_config_update(ctx->term); 119 termio_config_update(ctx->term);
120 _update_backlog_title(ctx);
98 config_save(config); 121 config_save(config);
99} 122}
100 123
@@ -187,6 +210,7 @@ _parent_del_cb(void *data,
187{ 210{
188 Behavior_Ctx *ctx = data; 211 Behavior_Ctx *ctx = data;
189 212
213 eina_stringshare_del(ctx->backlog_msg);
190 free(ctx); 214 free(ctx);
191} 215}
192 216
@@ -563,7 +587,8 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
563 o = elm_label_add(bx); 587 o = elm_label_add(bx);
564 evas_object_size_hint_weight_set(o, 0.0, 0.0); 588 evas_object_size_hint_weight_set(o, 0.0, 0.0);
565 evas_object_size_hint_align_set(o, 0.0, 0.5); 589 evas_object_size_hint_align_set(o, 0.0, 0.5);
566 elm_object_text_set(o, _("Scrollback:")); 590 ctx->backlock_label = o;
591 _update_backlog_title(ctx);
567 elm_box_pack_end(bx, o); 592 elm_box_pack_end(bx, o);
568 evas_object_show(o); 593 evas_object_show(o);
569 594
diff --git a/src/bin/options_elm.c b/src/bin/options_elm.c
index fa9689c..b68afd0 100644
--- a/src/bin/options_elm.c
+++ b/src/bin/options_elm.c
@@ -3,7 +3,9 @@
3#include <Elementary.h> 3#include <Elementary.h>
4#include "options.h" 4#include "options.h"
5#include "options_elm.h" 5#include "options_elm.h"
6#include "utils.h"
6 7
8static char *_elementary_config = NULL;
7static void 9static void
8launch_elm_config(void *_data EINA_UNUSED, 10launch_elm_config(void *_data EINA_UNUSED,
9 Evas_Object *_obj EINA_UNUSED, 11 Evas_Object *_obj EINA_UNUSED,
@@ -11,7 +13,7 @@ launch_elm_config(void *_data EINA_UNUSED,
11{ 13{
12 Ecore_Exe *exe; 14 Ecore_Exe *exe;
13 15
14 exe = ecore_exe_pipe_run("elementary_config", ECORE_EXE_NONE, NULL); 16 exe = ecore_exe_run(_elementary_config, NULL);
15 ecore_exe_free(exe); 17 ecore_exe_free(exe);
16} 18}
17 19
@@ -41,12 +43,66 @@ _scale_change(void *data EINA_UNUSED,
41 elm_config_all_flush(); 43 elm_config_all_flush();
42} 44}
43 45
46static void
47_find_binary(void)
48{
49 char *path_env = getenv("PATH");
50 char *names[] = { "elementary_config", "terminology.elementaryConfig"};
51 int i, n_names = sizeof(names) / sizeof(names[0]);
52
53 if (!path_env)
54 goto error;
55
56 for (i = 0; i < n_names; i++)
57 {
58 char *name = names[i];
59 char *start = path_env;
60 char *end = strchrnul(start, ':');
61 while (*start)
62 {
63 if (end > start)
64 {
65 struct stat st;
66 int res;
67 const char *lookup_path;
68 if (*end == '/')
69 lookup_path = eina_stringshare_printf("%.*s%s",
70 (int)(end - start),
71 start,
72 name);
73 else
74 lookup_path = eina_stringshare_printf("%.*s/%s",
75 (int)(end - start),
76 start,
77 name);
78 res = stat(lookup_path, &st);
79 eina_stringshare_del(lookup_path);
80 if (res == 0 && S_ISREG(st.st_mode) && (S_IXUSR & st.st_mode))
81 {
82 free(_elementary_config);
83 _elementary_config = strdup(name);
84 return;
85 }
86 }
87 if (!*end)
88 break;
89 start = end + 1;
90 end = strchrnul(start, ':');
91 }
92 }
93
94error:
95 _elementary_config = "elementary_config";
96}
97
44void 98void
45options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED) 99options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
46{ 100{
47 Evas_Object *o, *fr, *bx, *bt, *en, *lbl, *sl, *sp; 101 Evas_Object *o, *fr, *bx, *bt, *en, *lbl, *sl, *sp;
48 const char *txt; 102 const char *txt;
49 103
104 _find_binary();
105
50 fr = o = elm_frame_add(opbox); 106 fr = o = elm_frame_add(opbox);
51 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 107 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
52 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 108 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
@@ -62,8 +118,11 @@ options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
62 elm_entry_context_menu_disabled_set(en, EINA_TRUE); 118 elm_entry_context_menu_disabled_set(en, EINA_TRUE);
63 elm_entry_editable_set(en, EINA_FALSE); 119 elm_entry_editable_set(en, EINA_FALSE);
64 elm_entry_line_wrap_set(en, ELM_WRAP_MIXED); 120 elm_entry_line_wrap_set(en, ELM_WRAP_MIXED);
65 elm_object_text_set(en, _("<em>Terminology</em> uses the <hilight>elementary</hilight> toolkit.<br>" 121 txt = eina_stringshare_printf(
66 "The toolkit configuration settings can be accessed by running <keyword>elementary_config</keyword>.")); 122 _("<em>Terminology</em> uses the <hilight>elementary</hilight> toolkit.<br>"
123 "The toolkit configuration settings can be accessed by running <keyword>%s</keyword>."), _elementary_config);
124 elm_object_text_set(en, txt);
125 eina_stringshare_del(txt);
67 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0); 126 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0);
68 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5); 127 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
69 elm_box_pack_end(bx, en); 128 elm_box_pack_end(bx, en);
@@ -72,7 +131,9 @@ options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
72 bt = elm_button_add(opbox); 131 bt = elm_button_add(opbox);
73 evas_object_smart_callback_add(bt, "clicked", launch_elm_config, NULL); 132 evas_object_smart_callback_add(bt, "clicked", launch_elm_config, NULL);
74 evas_object_propagate_events_set(bt, EINA_FALSE); 133 evas_object_propagate_events_set(bt, EINA_FALSE);
75 elm_layout_text_set(bt, NULL, _("Launch elementary_config")); 134 txt = eina_stringshare_printf(_("Launch %s"), _elementary_config);
135 elm_layout_text_set(bt, NULL, txt);
136 eina_stringshare_del(txt);
76 elm_box_pack_end(bx, bt); 137 elm_box_pack_end(bx, bt);
77 evas_object_show(bt); 138 evas_object_show(bt);
78 139
diff --git a/src/bin/sb.c b/src/bin/sb.c
index a0dd9e8..f52f9d4 100644
--- a/src/bin/sb.c
+++ b/src/bin/sb.c
@@ -108,8 +108,17 @@ void
108ty_sb_lskip(struct ty_sb *sb, int len) 108ty_sb_lskip(struct ty_sb *sb, int len)
109{ 109{
110 sb->len -= len; 110 sb->len -= len;
111 sb->gap += len; 111 if (sb->len)
112 sb->buf += len; 112 {
113 sb->gap += len;
114 sb->buf += len;
115 }
116 else
117 {
118 /* buffer is empty, get rid of gap */
119 sb->buf -= sb->gap;
120 sb->gap = 0;
121 }
113} 122}
114 123
115void 124void
diff --git a/src/bin/termcmd.c b/src/bin/termcmd.c
index 3b2e733..e038bfc 100644
--- a/src/bin/termcmd.c
+++ b/src/bin/termcmd.c
@@ -57,15 +57,27 @@ _termcmd_font_size(Evas_Object *obj,
57 eina_stringshare_del(config->font.name); 57 eina_stringshare_del(config->font.name);
58 config->font.name = eina_stringshare_add("10x20.pcf"); 58 config->font.name = eina_stringshare_add("10x20.pcf");
59 } 59 }
60 new_size = 20; 60 new_size = config->font.size * 2;
61 } 61 }
62 else if (cmd[0] == '+') // size up 62 else if (cmd[0] == '+') // size up
63 { 63 {
64 new_size = config->font.size + 1; 64 int i;
65
66 new_size = config->font.size;
67 for (i = 0; cmd[i] == '+'; i++)
68 {
69 new_size = ((double)new_size * 1.4) + 1;
70 }
65 } 71 }
66 else if (cmd[0] == '-') // size down 72 else if (cmd[0] == '-') // size down
67 { 73 {
68 new_size = config->font.size - 1; 74 int i;
75
76 new_size = config->font.size;
77 for (i = 0; cmd[i] == '-'; i++)
78 {
79 new_size = (double)(new_size - 1) / 1.4;
80 }
69 } 81 }
70 else 82 else
71 { 83 {
diff --git a/src/bin/termio.c b/src/bin/termio.c
index dea782e..2d86ea7 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -6,6 +6,7 @@
6#include "termio.h" 6#include "termio.h"
7#include "termiolink.h" 7#include "termiolink.h"
8#include "termpty.h" 8#include "termpty.h"
9#include "backlog.h"
9#include "termptyops.h" 10#include "termptyops.h"
10#include "termcmd.h" 11#include "termcmd.h"
11#include "termptydbl.h" 12#include "termptydbl.h"
@@ -175,11 +176,8 @@ termio_user_title_set(Evas_Object *obj, const char *title)
175 size_t len = 0; 176 size_t len = 0;
176 EINA_SAFETY_ON_NULL_RETURN(sd); 177 EINA_SAFETY_ON_NULL_RETURN(sd);
177 178
178 if (sd->pty->prop.user_title) 179 eina_stringshare_del(sd->pty->prop.user_title);
179 { 180 sd->pty->prop.user_title = NULL;
180 eina_stringshare_del(sd->pty->prop.user_title);
181 sd->pty->prop.user_title = NULL;
182 }
183 181
184 if (title) 182 if (title)
185 { 183 {
@@ -408,7 +406,7 @@ termio_config_update(Evas_Object *obj)
408 406
409 EINA_SAFETY_ON_NULL_RETURN(sd); 407 EINA_SAFETY_ON_NULL_RETURN(sd);
410 408
411 if (sd->font.name) eina_stringshare_del(sd->font.name); 409 eina_stringshare_del(sd->font.name);
412 sd->font.name = NULL; 410 sd->font.name = NULL;
413 411
414 if (sd->config->font.bitmap) 412 if (sd->config->font.bitmap)
@@ -871,11 +869,8 @@ _lost_selection(void *data, Elm_Sel_Type selection)
871 } 869 }
872 if (sd->have_sel) 870 if (sd->have_sel)
873 { 871 {
874 if (sd->sel_str) 872 eina_stringshare_del(sd->sel_str);
875 { 873 sd->sel_str = NULL;
876 eina_stringshare_del(sd->sel_str);
877 sd->sel_str = NULL;
878 }
879 termio_sel_set(sd, EINA_FALSE); 874 termio_sel_set(sd, EINA_FALSE);
880 elm_object_cnp_selection_clear(sd->win, selection); 875 elm_object_cnp_selection_clear(sd->win, selection);
881 termio_smart_update_queue(sd); 876 termio_smart_update_queue(sd);
@@ -905,7 +900,7 @@ termio_take_selection_text(Termio *sd, Elm_Sel_Type type, const char *text)
905 elm_cnp_selection_loss_callback_set(sd->win, type, 900 elm_cnp_selection_loss_callback_set(sd->win, type,
906 _lost_selection, sd->self); 901 _lost_selection, sd->self);
907 sd->have_sel = EINA_TRUE; 902 sd->have_sel = EINA_TRUE;
908 if (sd->sel_str) eina_stringshare_del(sd->sel_str); 903 eina_stringshare_del(sd->sel_str);
909 sd->sel_str = text; 904 sd->sel_str = text;
910} 905}
911 906
@@ -1043,8 +1038,7 @@ _getsel_cb(void *data,
1043 int prev_i = i; 1038 int prev_i = i;
1044 g = eina_unicode_utf8_next_get(s, &i); 1039 g = eina_unicode_utf8_next_get(s, &i);
1045 /* Skip escape codes as a security measure */ 1040 /* Skip escape codes as a security measure */
1046 if ((g < '\n') || 1041 if (! ((g == '\t') || (g == '\n') || (g >= ' ')))
1047 ((g > '\n') && (g < ' ')))
1048 { 1042 {
1049 continue; 1043 continue;
1050 } 1044 }
@@ -1074,9 +1068,9 @@ _getsel_cb(void *data,
1074 const char *fmt = "UNKNOWN"; 1068 const char *fmt = "UNKNOWN";
1075 switch (ev->format) 1069 switch (ev->format)
1076 { 1070 {
1077 case ELM_SEL_FORMAT_TARGETS: fmt = "TARGETS"; break; /* shouldn't happen */ 1071 case ELM_SEL_FORMAT_TARGETS: fmt = "TARGETS"; break;
1078 case ELM_SEL_FORMAT_NONE: fmt = "NONE"; break; 1072 case ELM_SEL_FORMAT_NONE: fmt = "NONE"; break;
1079 case ELM_SEL_FORMAT_TEXT: fmt = "TEXT"; break; 1073 case ELM_SEL_FORMAT_TEXT: fmt = "TEXT"; break; /* shouldn't happen */
1080 case ELM_SEL_FORMAT_MARKUP: fmt = "MARKUP"; break; 1074 case ELM_SEL_FORMAT_MARKUP: fmt = "MARKUP"; break;
1081 case ELM_SEL_FORMAT_IMAGE: fmt = "IMAGE"; break; 1075 case ELM_SEL_FORMAT_IMAGE: fmt = "IMAGE"; break;
1082 case ELM_SEL_FORMAT_VCARD: fmt = "VCARD"; break; 1076 case ELM_SEL_FORMAT_VCARD: fmt = "VCARD"; break;
@@ -1439,11 +1433,9 @@ _remove_links(Termio *sd)
1439{ 1433{
1440 Eina_Bool same_geom = EINA_FALSE; 1434 Eina_Bool same_geom = EINA_FALSE;
1441 1435
1442 if (sd->link.string) 1436 eina_stringshare_del(sd->link.string);
1443 { 1437 sd->link.string = NULL;
1444 eina_stringshare_del(sd->link.string); 1438
1445 sd->link.string = NULL;
1446 }
1447 sd->link.x1 = -1; 1439 sd->link.x1 = -1;
1448 sd->link.y1 = -1; 1440 sd->link.y1 = -1;
1449 sd->link.x2 = -1; 1441 sd->link.x2 = -1;
@@ -2383,8 +2375,7 @@ _smart_mouseover_apply(Termio *sd)
2383 goto end; 2375 goto end;
2384 } 2376 }
2385 2377
2386 if (sd->link.string) 2378 eina_stringshare_del(sd->link.string);
2387 eina_stringshare_del(sd->link.string);
2388 sd->link.string = eina_stringshare_add(s); 2379 sd->link.string = eina_stringshare_add(s);
2389 2380
2390 if ((x1 == sd->link.x1) && (y1 == sd->link.y1) && 2381 if ((x1 == sd->link.x1) && (y1 == sd->link.y1) &&
@@ -2829,13 +2820,13 @@ termio_file_send_ok(const Evas_Object *obj, const char *file)
2829 sd->sendfile.f = fopen(file, "w"); 2820 sd->sendfile.f = fopen(file, "w");
2830 if (sd->sendfile.f) 2821 if (sd->sendfile.f)
2831 { 2822 {
2832 if (sd->sendfile.file) eina_stringshare_del(sd->sendfile.file); 2823 eina_stringshare_del(sd->sendfile.file);
2833 sd->sendfile.file = eina_stringshare_add(file); 2824 sd->sendfile.file = eina_stringshare_add(file);
2834 sd->sendfile.active = EINA_TRUE; 2825 sd->sendfile.active = EINA_TRUE;
2835 termpty_write(ty, "k\n", 2); 2826 termpty_write(ty, "k\n", 2);
2836 return EINA_TRUE; 2827 return EINA_TRUE;
2837 } 2828 }
2838 if (sd->sendfile.file) eina_stringshare_del(sd->sendfile.file); 2829 eina_stringshare_del(sd->sendfile.file);
2839 sd->sendfile.file = NULL; 2830 sd->sendfile.file = NULL;
2840 sd->sendfile.active = EINA_FALSE; 2831 sd->sendfile.active = EINA_FALSE;
2841 termpty_write(ty, "n\n", 2); 2832 termpty_write(ty, "n\n", 2);
@@ -3226,10 +3217,9 @@ _smart_del(Evas_Object *obj)
3226 if (sd->link_do_timer) ecore_timer_del(sd->link_do_timer); 3217 if (sd->link_do_timer) ecore_timer_del(sd->link_do_timer);
3227 if (sd->mouse_move_job) ecore_job_del(sd->mouse_move_job); 3218 if (sd->mouse_move_job) ecore_job_del(sd->mouse_move_job);
3228 if (sd->mouseover_delay) ecore_timer_del(sd->mouseover_delay); 3219 if (sd->mouseover_delay) ecore_timer_del(sd->mouseover_delay);
3229 if (sd->font.name) eina_stringshare_del(sd->font.name); 3220 eina_stringshare_del(sd->font.name);
3230 if (sd->pty) termpty_free(sd->pty); 3221 if (sd->pty) termpty_free(sd->pty);
3231 if (sd->link.string) 3222 eina_stringshare_del(sd->link.string);
3232 eina_stringshare_del(sd->link.string);
3233 if (sd->glayer) evas_object_del(sd->glayer); 3223 if (sd->glayer) evas_object_del(sd->glayer);
3234 if (sd->win) 3224 if (sd->win)
3235 evas_object_event_callback_del_full(sd->win, EVAS_CALLBACK_DEL, 3225 evas_object_event_callback_del_full(sd->win, EVAS_CALLBACK_DEL,
@@ -3255,7 +3245,7 @@ _smart_del(Evas_Object *obj)
3255 } 3245 }
3256 sd->sendfile.active = EINA_FALSE; 3246 sd->sendfile.active = EINA_FALSE;
3257 } 3247 }
3258 if (sd->sel_str) eina_stringshare_del(sd->sel_str); 3248 eina_stringshare_del(sd->sel_str);
3259 if (sd->sel_reset_job) ecore_job_del(sd->sel_reset_job); 3249 if (sd->sel_reset_job) ecore_job_del(sd->sel_reset_job);
3260 EINA_LIST_FREE(sd->cur_chids, chid) eina_stringshare_del(chid); 3250 EINA_LIST_FREE(sd->cur_chids, chid) eina_stringshare_del(chid);
3261 sd->sel_str = NULL; 3251 sd->sel_str = NULL;
@@ -3800,11 +3790,8 @@ _smart_pty_command(void *data)
3800 { 3790 {
3801 sd->sendfile.progress = 0.0; 3791 sd->sendfile.progress = 0.0;
3802 sd->sendfile.size = 0; 3792 sd->sendfile.size = 0;
3803 if (sd->sendfile.file) 3793 eina_stringshare_del(sd->sendfile.file);
3804 { 3794 sd->sendfile.file = NULL;
3805 eina_stringshare_del(sd->sendfile.file);
3806 sd->sendfile.file = NULL;
3807 }
3808 if (sd->sendfile.f) 3795 if (sd->sendfile.f)
3809 { 3796 {
3810 fclose(sd->sendfile.f); 3797 fclose(sd->sendfile.f);
diff --git a/src/bin/termiointernals.c b/src/bin/termiointernals.c
index 555c27a..cd17b29 100644
--- a/src/bin/termiointernals.c
+++ b/src/bin/termiointernals.c
@@ -5,6 +5,7 @@
5#include "termio.h" 5#include "termio.h"
6#include "miniview.h" 6#include "miniview.h"
7#include "termpty.h" 7#include "termpty.h"
8#include "backlog.h"
8#include "termptydbl.h" 9#include "termptydbl.h"
9#include "termptyops.h" 10#include "termptyops.h"
10#include "termiointernals.h" 11#include "termiointernals.h"
@@ -21,6 +22,16 @@ termio_selection_get(Termio *sd,
21{ 22{
22 int x, y; 23 int x, y;
23 24
25#define SB_ADD(STR, LEN) do { \
26 if (ty_sb_add(sb, STR, LEN) < 0) \
27 goto err; \
28} while (0)
29
30#define RTRIM() do { \
31 if (rtrim) \
32 ty_sb_spaces_rtrim(sb); \
33} while (0)
34
24 termpty_backlog_lock(); 35 termpty_backlog_lock();
25 for (y = c1y; y <= c2y; y++) 36 for (y = c1y; y <= c2y; y++)
26 { 37 {
@@ -33,51 +44,91 @@ termio_selection_get(Termio *sd,
33 cells = termpty_cellrow_get(sd->pty, y, &w); 44 cells = termpty_cellrow_get(sd->pty, y, &w);
34 if (!cells || !w) 45 if (!cells || !w)
35 { 46 {
36 if (ty_sb_add(sb, "\n", 1) < 0) goto err; 47 SB_ADD("\n", 1);
37 continue; 48 continue;
38 } 49 }
39 if (w > sd->grid.w) w = sd->grid.w; 50
51 /* Define how much needs to be read on that line */
52 if (w > sd->grid.w)
53 w = sd->grid.w;
40 if (y == c1y && c1x >= w) 54 if (y == c1y && c1x >= w)
41 { 55 {
42 if (rtrim) 56 RTRIM();
43 ty_sb_spaces_rtrim(sb); 57 SB_ADD("\n", 1);
44 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
45 continue; 58 continue;
46 } 59 }
47 start_x = c1x; 60 start_x = c1x;
48 end_x = (c2x >= w) ? w - 1 : c2x; 61 end_x = (c2x >= w) ? w - 1 : c2x;
49 if (c1y != c2y) 62 if (c1y != c2y)
50 { 63 {
51 if (y == c1y) end_x = w - 1; 64 if (y == c1y)
52 else if (y == c2y) start_x = 0; 65 end_x = w - 1;
66 else if (y == c2y)
67 start_x = 0;
53 else 68 else
54 { 69 {
55 start_x = 0; 70 start_x = 0;
56 end_x = w - 1; 71 end_x = w - 1;
57 } 72 }
58 } 73 }
74
59 for (x = start_x; x <= end_x; x++) 75 for (x = start_x; x <= end_x; x++)
60 { 76 {
61 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth)) 77 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth))
62 { 78 {
63 if (x < end_x) x++; 79 if (x < end_x)
64 else break; 80 x++;
81 else
82 break;
83 }
84 if (x >= w)
85 break;
86 if (cells[x].att.tab_inserted)
87 {
88 /* There was a tab inserted.
89 * Only output it if there were spaces/empty cells "bellow"
90 */
91 Eina_Bool is_tab = EINA_TRUE;
92 while ((is_tab) && (x < end_x))
93 {
94 if (((cells[x].codepoint == 0) ||
95 (cells[x].att.invisible == 1) ||
96 (cells[x].codepoint == ' ')))
97 {
98 x++;
99 }
100 else
101 {
102 is_tab = EINA_FALSE;
103 }
104 if (cells[x].att.tab_last)
105 {
106 SB_ADD("\t", 1);
107 if (is_tab)
108 {
109 x++;
110 is_tab = EINA_FALSE;
111 }
112 break;
113 }
114 }
65 } 115 }
66 if (x >= w) break;
67 if (cells[x].att.newline) 116 if (cells[x].att.newline)
68 { 117 {
69 last0 = -1; 118 last0 = -1;
70 if ((y != c2y) || (x != end_x)) 119 if ((y != c2y) || (x != end_x))
71 { 120 {
72 if (rtrim) 121 RTRIM();
73 ty_sb_spaces_rtrim(sb); 122 SB_ADD("\n", 1);
74 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
75 } 123 }
76 break; 124 break;
77 } 125 }
78 else if (cells[x].codepoint == 0) 126 else if (cells[x].codepoint == 0)
79 { 127 {
80 if (last0 < 0) last0 = x; 128 /* empty cell, track it to know whether to replace with
129 * spaces */
130 if (last0 < 0)
131 last0 = x;
81 } 132 }
82 else 133 else
83 { 134 {
@@ -90,27 +141,28 @@ termio_selection_get(Termio *sd,
90 last0 = -1; 141 last0 = -1;
91 while (v >= 0) 142 while (v >= 0)
92 { 143 {
93 if (ty_sb_add(sb, " ", 1) < 0) goto err; 144 SB_ADD(" ", 1);
94 v--; 145 v--;
95 } 146 }
96 } 147 }
97 txtlen = codepoint_to_utf8(cells[x].codepoint, txt); 148 txtlen = codepoint_to_utf8(cells[x].codepoint, txt);
98 if (txtlen > 0) 149 if (txtlen > 0)
99 if (ty_sb_add(sb, txt, txtlen) < 0) goto err; 150 SB_ADD(txt, txtlen);
100 if ((x == (w - 1)) && 151 if ((x == (w - 1)) &&
101 ((x != c2x) || (y != c2y))) 152 ((x != c2x) || (y != c2y)))
102 { 153 {
103 if (!cells[x].att.autowrapped) 154 if (!cells[x].att.autowrapped)
104 { 155 {
105 if (rtrim) 156 RTRIM();
106 ty_sb_spaces_rtrim(sb); 157 SB_ADD("\n", 1);
107 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
108 } 158 }
109 } 159 }
110 } 160 }
111 } 161 }
112 if (last0 >= 0) 162 if (last0 >= 0)
113 { 163 {
164 /* line stop by empty cell, need to know whether to insert spaces
165 * or just go to next line */
114 if (y == c2y) 166 if (y == c2y)
115 { 167 {
116 Eina_Bool have_more = EINA_FALSE; 168 Eina_Bool have_more = EINA_FALSE;
@@ -120,8 +172,10 @@ termio_selection_get(Termio *sd,
120 if ((cells[x].codepoint == 0) && 172 if ((cells[x].codepoint == 0) &&
121 (cells[x].att.dblwidth)) 173 (cells[x].att.dblwidth))
122 { 174 {
123 if (x < (w - 1)) x++; 175 if (x < (w - 1))
124 else break; 176 x++;
177 else
178 break;
125 } 179 }
126 if (((cells[x].codepoint != 0) && 180 if (((cells[x].codepoint != 0) &&
127 (cells[x].codepoint != ' ')) || 181 (cells[x].codepoint != ' ')) ||
@@ -133,9 +187,8 @@ termio_selection_get(Termio *sd,
133 } 187 }
134 if (!have_more) 188 if (!have_more)
135 { 189 {
136 if (rtrim) 190 RTRIM();
137 ty_sb_spaces_rtrim(sb); 191 SB_ADD("\n", 1);
138 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
139 } 192 }
140 else 193 else
141 { 194 {
@@ -144,31 +197,34 @@ termio_selection_get(Termio *sd,
144 if ((cells[x].codepoint == 0) && 197 if ((cells[x].codepoint == 0) &&
145 (cells[x].att.dblwidth)) 198 (cells[x].att.dblwidth))
146 { 199 {
147 if (x < (w - 1)) x++; 200 if (x < (w - 1))
148 else break; 201 x++;
202 else
203 break;
149 } 204 }
150 if (x >= w) break; 205 if (x >= w)
151 if (ty_sb_add(sb, " ", 1) < 0) goto err; 206 break;
207 SB_ADD(" ", 1);
152 } 208 }
153 } 209 }
154 } 210 }
155 else 211 else
156 { 212 {
157 if (rtrim) 213 RTRIM();
158 ty_sb_spaces_rtrim(sb); 214 SB_ADD("\n", 1);
159 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
160 } 215 }
161 } 216 }
162 } 217 }
163 termpty_backlog_unlock(); 218 termpty_backlog_unlock();
164 219
165 if (rtrim) 220 RTRIM();
166 ty_sb_spaces_rtrim(sb);
167 221
168 return; 222 return;
169 223
170err: 224err:
171 ty_sb_free(sb); 225 ty_sb_free(sb);
226#undef SB_ADD
227#undef RTRIM
172} 228}
173 229
174 230
@@ -359,9 +415,21 @@ termio_internal_get_selection(Termio *sd, size_t *lenp)
359 415
360 if (isb.len) 416 if (isb.len)
361 { 417 {
418 int res;
362 if (isb.buf[isb.len - 1] != '\n' && i != end_y) 419 if (isb.buf[isb.len - 1] != '\n' && i != end_y)
363 ty_sb_add(&isb, "\n", 1); 420 {
364 ty_sb_add(&sb, isb.buf, isb.len); 421 res = ty_sb_add(&isb, "\n", 1);
422 if (res < 0)
423 {
424 ERR("failure to add newline to selection buffer");
425 }
426 }
427 res = ty_sb_add(&sb, isb.buf, isb.len);
428 if (res < 0)
429 {
430 ERR("failure to add %zd characters to selection buffer",
431 isb.len);
432 }
365 } 433 }
366 ty_sb_free(&isb); 434 ty_sb_free(&isb);
367 } 435 }
@@ -1305,8 +1373,6 @@ _selection_newline_extend_fix(Termio *sd)
1305 termpty_backlog_unlock(); 1373 termpty_backlog_unlock();
1306} 1374}
1307 1375
1308/* }}} */
1309
1310void 1376void
1311termio_selection_dbl_fix(Termio *sd) 1377termio_selection_dbl_fix(Termio *sd)
1312{ 1378{
@@ -1393,6 +1459,7 @@ termio_selection_dbl_fix(Termio *sd)
1393 sd->pty->selection.end.y = end_y; 1459 sd->pty->selection.end.y = end_y;
1394} 1460}
1395 1461
1462/* }}} */
1396 1463
1397static void 1464static void
1398_handle_mouse_down_single_click(Termio *sd, 1465_handle_mouse_down_single_click(Termio *sd,
diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
index d5a3fd5..8a0696b 100644
--- a/src/bin/termiolink.c
+++ b/src/bin/termiolink.c
@@ -1,5 +1,7 @@
1#include "private.h" 1#include "private.h"
2#include <Elementary.h> 2#include <Elementary.h>
3#include "termpty.h"
4#include "backlog.h"
3#include "termiolink.h" 5#include "termiolink.h"
4#include "termio.h" 6#include "termio.h"
5#include "sb.h" 7#include "sb.h"
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 879135f..8349097 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -6,7 +6,7 @@
6#include "termpty.h" 6#include "termpty.h"
7#include "termptyesc.h" 7#include "termptyesc.h"
8#include "termptyops.h" 8#include "termptyops.h"
9#include "termptysave.h" 9#include "backlog.h"
10#include "keyin.h" 10#include "keyin.h"
11#if !defined(ENABLE_FUZZING) && !defined(ENABLE_TESTS) 11#if !defined(ENABLE_FUZZING) && !defined(ENABLE_TESTS)
12# include "win.h" 12# include "win.h"
@@ -225,35 +225,13 @@ _pty_size(Termpty *ty)
225} 225}
226 226
227static Eina_Bool 227static Eina_Bool
228_fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty) 228_handle_read(Termpty *ty, Eina_Bool false_on_empty)
229{ 229{
230 char buf[4097]; 230 char buf[4097];
231 Eina_Unicode codepoint[4097]; 231 Eina_Unicode codepoint[4097];
232 int len, i, j, reads; 232 int len, i, j, reads;
233 unsigned int k; 233 unsigned int k;
234 234
235 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
236 {
237 DBG("error while reading from tty slave fd");
238 ty->hand_fd = NULL;
239 return ECORE_CALLBACK_CANCEL;
240 }
241 if (ty->fd == -1)
242 {
243 ty->hand_fd = NULL;
244 return ECORE_CALLBACK_CANCEL;
245 }
246
247/* it seems the BSDs can not read from this side of the pair if the other side
248 * is closed */
249#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__)
250 if (ty->pid == -1)
251 {
252 ty->hand_fd = NULL;
253 return ECORE_CALLBACK_CANCEL;
254 }
255#endif
256
257 // read up to 64 * 4096 bytes 235 // read up to 64 * 4096 bytes
258 for (reads = 0; reads < 64; reads++) 236 for (reads = 0; reads < 64; reads++)
259 { 237 {
@@ -268,7 +246,7 @@ _fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty)
268 } 246 }
269 errno = 0; 247 errno = 0;
270 len = read(ty->fd, rbuf, len); 248 len = read(ty->fd, rbuf, len);
271 if ((len < 0 && errno != EAGAIN) || 249 if ((len < 0 && !(errno == EAGAIN || errno == EINTR)) ||
272 (len == 0 && errno != 0)) 250 (len == 0 && errno != 0))
273 { 251 {
274 /* Do not print error if the child has exited */ 252 /* Do not print error if the child has exited */
@@ -278,7 +256,8 @@ _fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty)
278 } 256 }
279 close(ty->fd); 257 close(ty->fd);
280 ty->fd = -1; 258 ty->fd = -1;
281 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 259 if (ty->hand_fd)
260 ecore_main_fd_handler_del(ty->hand_fd);
282 ty->hand_fd = NULL; 261 ty->hand_fd = NULL;
283 return ECORE_CALLBACK_CANCEL; 262 return ECORE_CALLBACK_CANCEL;
284 } 263 }
@@ -337,16 +316,19 @@ _fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty)
337// DBG("---------------- handle buf %i", j); 316// DBG("---------------- handle buf %i", j);
338 termpty_handle_buf(ty, codepoint, j); 317 termpty_handle_buf(ty, codepoint, j);
339 } 318 }
340 if (ty->cb.change.func) ty->cb.change.func(ty->cb.change.data); 319 if (ty->cb.change.func)
320 ty->cb.change.func(ty->cb.change.data);
341#if defined(ENABLE_FUZZING) || defined(ENABLE_TESTS) 321#if defined(ENABLE_FUZZING) || defined(ENABLE_TESTS)
342 if (len <= 0) 322 if (len <= 0)
343 { 323 {
344 ty->exit_code = 0; 324 ty->exit_code = 0;
345 ty->pid = -1; 325 ty->pid = -1;
346 326
347 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); 327 if (ty->hand_exe_exit)
328 ecore_event_handler_del(ty->hand_exe_exit);
348 ty->hand_exe_exit = NULL; 329 ty->hand_exe_exit = NULL;
349 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 330 if (ty->hand_fd)
331 ecore_main_fd_handler_del(ty->hand_fd);
350 ty->hand_fd = NULL; 332 ty->hand_fd = NULL;
351 ty->fd = -1; 333 ty->fd = -1;
352 ty->slavefd = -1; 334 ty->slavefd = -1;
@@ -355,14 +337,80 @@ _fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty)
355 return ECORE_CALLBACK_CANCEL; 337 return ECORE_CALLBACK_CANCEL;
356 } 338 }
357#endif 339#endif
358 if ((false_on_empty) && (len <= 0)) return ECORE_CALLBACK_CANCEL; 340 if ((false_on_empty) && (len <= 0))
359 return EINA_TRUE; 341 return ECORE_CALLBACK_CANCEL;
342
343 return ECORE_CALLBACK_RENEW;
344}
345
346static Eina_Bool
347_handle_write(Termpty *ty)
348{
349 struct ty_sb *sb = &ty->write_buffer;
350 ssize_t len;
351
352 if (!sb->len)
353 return ECORE_CALLBACK_RENEW;
354
355 len = write(ty->fd, sb->buf, sb->len);
356 if (len < 0 && (errno != EINTR && errno != EAGAIN))
357 {
358 ERR(_("Could not write to file descriptor %d: %s"),
359 ty->fd, strerror(errno));
360 return ECORE_CALLBACK_CANCEL;
361 }
362 ty_sb_lskip(sb, len);
363
364 if (!sb->len)
365 ecore_main_fd_handler_active_set(ty->hand_fd,
366 ECORE_FD_ERROR |
367 ECORE_FD_READ);
368
369 return ECORE_CALLBACK_RENEW;
370}
371
372static Eina_Bool
373_fd_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty)
374{
375 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
376 {
377 DBG("error while doing I/O on tty slave fd");
378 ty->hand_fd = NULL;
379 return ECORE_CALLBACK_CANCEL;
380 }
381 if (ty->fd == -1)
382 {
383 ty->hand_fd = NULL;
384 return ECORE_CALLBACK_CANCEL;
385 }
386
387 // it seems the BSDs can not read from this side of the pair if the other side
388 // is closed ... but no longer just bsd's - i have seen this now on linux
389 if (ty->pid == -1)
390 {
391 ty->hand_fd = NULL;
392 return ECORE_CALLBACK_CANCEL;
393 }
394
395 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
396 {
397 if (!_handle_read(ty, false_on_empty))
398 return ECORE_CALLBACK_CANCEL;
399 }
400
401 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
402 {
403 if (!_handle_write(ty))
404 return ECORE_CALLBACK_CANCEL;
405 }
406
407 return ECORE_CALLBACK_PASS_ON;
360} 408}
361 409
362static Eina_Bool 410static Eina_Bool
363_cb_fd_read(void *data, Ecore_Fd_Handler *fd_handler) 411_cb_fd(void *data, Ecore_Fd_Handler *fd_handler)
364{ 412{
365 return _fd_read_do(data, fd_handler, EINA_FALSE); 413 return _fd_do(data, fd_handler, EINA_FALSE);
366} 414}
367 415
368static Eina_Bool 416static Eina_Bool
@@ -386,7 +434,7 @@ _cb_exe_exit(void *data,
386 res = ECORE_CALLBACK_PASS_ON; 434 res = ECORE_CALLBACK_PASS_ON;
387 while (ty->hand_fd && res != ECORE_CALLBACK_CANCEL) 435 while (ty->hand_fd && res != ECORE_CALLBACK_CANCEL)
388 { 436 {
389 res = _fd_read_do(ty, ty->hand_fd, EINA_TRUE); 437 res = _fd_do(ty, ty->hand_fd, EINA_TRUE);
390 } 438 }
391 439
392 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 440 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd);
@@ -533,7 +581,7 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
533 ty->fd = STDIN_FILENO; 581 ty->fd = STDIN_FILENO;
534 ty->hand_fd = ecore_main_fd_handler_add(ty->fd, 582 ty->hand_fd = ecore_main_fd_handler_add(ty->fd,
535 ECORE_FD_READ | ECORE_FD_ERROR, 583 ECORE_FD_READ | ECORE_FD_ERROR,
536 _cb_fd_read, ty, 584 _cb_fd, ty,
537 NULL, NULL); 585 NULL, NULL);
538 _pty_size(ty); 586 _pty_size(ty);
539 termpty_save_register(ty); 587 termpty_save_register(ty);
@@ -728,6 +776,9 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
728 snprintf(buf, sizeof(buf), "WINDOWID=%lu", window_id); 776 snprintf(buf, sizeof(buf), "WINDOWID=%lu", window_id);
729 putenv(buf); 777 putenv(buf);
730 } 778 }
779#if ((EFL_VERSION_MAJOR > 1) || (EFL_VERSION_MINOR >= 24)) || ((EFL_VERSION_MAJOR == 1) && (EFL_VERSION_MINOR == 23) && (EFL_VERSION_MICRO == 99))
780 eina_file_close_from(3, NULL);
781#endif
731 if (!login_shell) 782 if (!login_shell)
732 execvp(args[0], (char *const *)args); 783 execvp(args[0], (char *const *)args);
733 else 784 else
@@ -747,10 +798,10 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
747 ty->slavefd = -1; 798 ty->slavefd = -1;
748 799
749 ty->hand_fd = ecore_main_fd_handler_add(ty->fd, ECORE_FD_READ, 800 ty->hand_fd = ecore_main_fd_handler_add(ty->fd, ECORE_FD_READ,
750 _cb_fd_read, ty, 801 _cb_fd, ty,
751 NULL, NULL); 802 NULL, NULL);
752 /* ensure we're not missing a read */ 803 /* ensure we're not missing a read */
753 _cb_fd_read(ty, ty->hand_fd); 804 _cb_fd(ty, ty->hand_fd);
754 805
755 _pty_size(ty); 806 _pty_size(ty);
756 termpty_save_register(ty); 807 termpty_save_register(ty);
@@ -818,17 +869,10 @@ termpty_free(Termpty *ty)
818 } 869 }
819 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); 870 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit);
820 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 871 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd);
821 if (ty->prop.title) eina_stringshare_del(ty->prop.title); 872 eina_stringshare_del(ty->prop.title);
822 if (ty->prop.user_title) eina_stringshare_del(ty->prop.user_title); 873 eina_stringshare_del(ty->prop.user_title);
823 if (ty->prop.icon) eina_stringshare_del(ty->prop.icon); 874 eina_stringshare_del(ty->prop.icon);
824 if (ty->back) 875 termpty_backlog_free(ty);
825 {
826 size_t i;
827
828 for (i = 0; i < ty->backsize; i++)
829 termpty_save_free(ty, &ty->back[i]);
830 free(ty->back);
831 }
832 free(ty->screen); 876 free(ty->screen);
833 free(ty->screen2); 877 free(ty->screen2);
834 if (ty->hl.links) 878 if (ty->hl.links)
@@ -846,6 +890,7 @@ termpty_free(Termpty *ty)
846 free(ty->hl.bitmap); 890 free(ty->hl.bitmap);
847 free(ty->buf); 891 free(ty->buf);
848 free(ty->tabs); 892 free(ty->tabs);
893 ty_sb_free(&ty->write_buffer);
849 free(ty); 894 free(ty);
850} 895}
851 896
@@ -901,83 +946,6 @@ termpty_line_length(const Termcell *cells, ssize_t nb_cells)
901 return 0; 946 return 0;
902} 947}
903 948
904#define BACKLOG_ROW_GET(Ty, Y) \
905 (&Ty->back[(Ty->backsize + ty->backpos - ((Y) - 1 )) % Ty->backsize])
906
907
908static inline void
909verify_beacon(const Termpty *ty EINA_UNUSED, int verbose EINA_UNUSED)
910{
911#if 0
912 Termsave *ts;
913 int nb_lines;
914 int backlog_y = ty->backlog_beacon.backlog_y;
915 int screen_y = ty->backlog_beacon.screen_y;
916
917 assert(ty->backlog_beacon.screen_y >= 0);
918 assert(ty->backlog_beacon.backlog_y >= 0);
919 assert(ty->backlog_beacon.screen_y >= ty->backlog_beacon.backlog_y);
920
921 if (verbose)
922 {
923 ERR("FROM screen_y:%d backlog_y:%d",
924 screen_y, backlog_y);
925 }
926 while (backlog_y > 0)
927 {
928 ts = BACKLOG_ROW_GET(ty, backlog_y);
929 if (!ts->cells)
930 {
931 if (verbose)
932 {
933 ERR("went too far: screen_y:%d backlog_y:%d",
934 screen_y, backlog_y);
935 }
936 return;
937 }
938
939 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
940 screen_y -= nb_lines;
941 backlog_y--;
942 if (verbose)
943 {
944 ERR("nb_lines:%d screen_y:%d backlog_y:%d ts->w:%d ty->w:%d",
945 nb_lines, screen_y, backlog_y, ts->w, ty->w);
946 }
947 assert(screen_y >= backlog_y);
948
949 }
950 if (verbose)
951 {
952 ERR("TO screen_y:%d backlog_y:%d",
953 screen_y, backlog_y);
954 }
955 assert (backlog_y == 0);
956 assert (screen_y == 0);
957#endif
958}
959
960static void
961_backlog_remove_latest_nolock(Termpty *ty)
962{
963 Termsave *ts;
964 if (ty->backsize == 0)
965 return;
966 ts = BACKLOG_ROW_GET(ty, 1);
967
968 if (ty->backpos == 0)
969 ty->backpos = ty->backsize - 1;
970 else
971 ty->backpos--;
972
973 /* reset beacon */
974 ty->backlog_beacon.screen_y = 0;
975 ty->backlog_beacon.backlog_y = 0;
976 verify_beacon(ty, 0);
977
978 termpty_save_free(ty, ts);
979}
980
981 949
982void 950void
983termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max) 951termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
@@ -989,7 +957,6 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
989 return; 957 return;
990 assert(ty->back); 958 assert(ty->back);
991 959
992 verify_beacon(ty, 0);
993 termpty_backlog_lock(); 960 termpty_backlog_lock();
994 961
995 w = termpty_line_length(cells, w_max); 962 w = termpty_line_length(cells, w_max);
@@ -1009,7 +976,6 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
1009 termpty_save_expand(ty, ts, cells, w); 976 termpty_save_expand(ty, ts, cells, w);
1010 ty->backlog_beacon.screen_y += (ts->w + ty->w - 1) / ty->w 977 ty->backlog_beacon.screen_y += (ts->w + ty->w - 1) / ty->w
1011 - (old_len + ty->w - 1) / ty->w; 978 - (old_len + ty->w - 1) / ty->w;
1012 verify_beacon(ty, 0);
1013 return; 979 return;
1014 } 980 }
1015 } 981 }
@@ -1032,7 +998,6 @@ add_new_ts:
1032 ty->backlog_beacon.screen_y = 0; 998 ty->backlog_beacon.screen_y = 0;
1033 ty->backlog_beacon.backlog_y = 0; 999 ty->backlog_beacon.backlog_y = 0;
1034 } 1000 }
1035 verify_beacon(ty, 0);
1036} 1001}
1037 1002
1038 1003
@@ -1049,42 +1014,12 @@ termpty_row_length(Termpty *ty, int y)
1049 return wret; 1014 return wret;
1050} 1015}
1051 1016
1052ssize_t
1053termpty_backlog_length(Termpty *ty)
1054{
1055 int backlog_y = ty->backlog_beacon.backlog_y;
1056 int screen_y = ty->backlog_beacon.screen_y;
1057
1058 if (!ty->backsize)
1059 return 0;
1060 verify_beacon(ty, 0);
1061
1062 for (backlog_y++; backlog_y < (int)ty->backsize; backlog_y++)
1063 {
1064 int nb_lines;
1065 const Termsave *ts;
1066
1067 ts = BACKLOG_ROW_GET(ty, backlog_y);
1068 if (!ts->cells)
1069 goto end;
1070
1071 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
1072 screen_y += nb_lines;
1073 ty->backlog_beacon.screen_y = screen_y;
1074 ty->backlog_beacon.backlog_y = backlog_y;
1075 verify_beacon(ty, 0);
1076 }
1077end:
1078 return ty->backlog_beacon.screen_y;
1079}
1080
1081void 1017void
1082termpty_backscroll_adjust(Termpty *ty, int *scroll) 1018termpty_backscroll_adjust(Termpty *ty, int *scroll)
1083{ 1019{
1084 int backlog_y = ty->backlog_beacon.backlog_y; 1020 int backlog_y = ty->backlog_beacon.backlog_y;
1085 int screen_y = ty->backlog_beacon.screen_y; 1021 int screen_y = ty->backlog_beacon.screen_y;
1086 1022
1087 verify_beacon(ty, 0);
1088 if ((ty->backsize == 0) || (*scroll <= 0)) 1023 if ((ty->backsize == 0) || (*scroll <= 0))
1089 { 1024 {
1090 *scroll = 0; 1025 *scroll = 0;
@@ -1092,7 +1027,6 @@ termpty_backscroll_adjust(Termpty *ty, int *scroll)
1092 } 1027 }
1093 if (*scroll < screen_y) 1028 if (*scroll < screen_y)
1094 { 1029 {
1095 verify_beacon(ty, 0);
1096 return; 1030 return;
1097 } 1031 }
1098 1032
@@ -1106,18 +1040,15 @@ termpty_backscroll_adjust(Termpty *ty, int *scroll)
1106 if (!ts->cells || backlog_y >= (int)ty->backsize) 1040 if (!ts->cells || backlog_y >= (int)ty->backsize)
1107 { 1041 {
1108 *scroll = ty->backlog_beacon.screen_y; 1042 *scroll = ty->backlog_beacon.screen_y;
1109 verify_beacon(ty, 0);
1110 return; 1043 return;
1111 } 1044 }
1112 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w; 1045 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
1113 screen_y += nb_lines; 1046 screen_y += nb_lines;
1114 ty->backlog_beacon.screen_y = screen_y; 1047 ty->backlog_beacon.screen_y = screen_y;
1115 ty->backlog_beacon.backlog_y = backlog_y; 1048 ty->backlog_beacon.backlog_y = backlog_y;
1116 verify_beacon(ty, 0);
1117 backlog_y++; 1049 backlog_y++;
1118 if (*scroll <= screen_y) 1050 if (*scroll <= screen_y)
1119 { 1051 {
1120 verify_beacon(ty, 0);
1121 return; 1052 return;
1122 } 1053 }
1123 } 1054 }
@@ -1141,7 +1072,6 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
1141 ty->backlog_beacon.backlog_y = 0; 1072 ty->backlog_beacon.backlog_y = 0;
1142 ty->backlog_beacon.screen_y = 0; 1073 ty->backlog_beacon.screen_y = 0;
1143 } 1074 }
1144 verify_beacon(ty, 0);
1145 1075
1146 /* going upward */ 1076 /* going upward */
1147 while (requested_y >= screen_y) 1077 while (requested_y >= screen_y)
@@ -1160,7 +1090,6 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
1160 screen_y += nb_lines; 1090 screen_y += nb_lines;
1161 ty->backlog_beacon.screen_y = screen_y; 1091 ty->backlog_beacon.screen_y = screen_y;
1162 ty->backlog_beacon.backlog_y = backlog_y; 1092 ty->backlog_beacon.backlog_y = backlog_y;
1163 verify_beacon(ty, 0);
1164 } 1093 }
1165 1094
1166 if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y)) 1095 if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y))
@@ -1187,7 +1116,6 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
1187 1116
1188 ty->backlog_beacon.screen_y = screen_y; 1117 ty->backlog_beacon.screen_y = screen_y;
1189 ty->backlog_beacon.backlog_y = backlog_y; 1118 ty->backlog_beacon.backlog_y = backlog_y;
1190 verify_beacon(ty, 0);
1191 1119
1192 if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y)) 1120 if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y))
1193 { 1121 {
@@ -1251,18 +1179,22 @@ termpty_cell_get(Termpty *ty, int y_requested, int x_requested)
1251void 1179void
1252termpty_write(Termpty *ty, const char *input, int len) 1180termpty_write(Termpty *ty, const char *input, int len)
1253{ 1181{
1254#if defined(ENABLE_TESTS)
1255 ty_sb_add(&ty->write_buffer, input, len);
1256#else
1257 int fd = ty->fd;
1258#if defined(ENABLE_FUZZING) 1182#if defined(ENABLE_FUZZING)
1259 fd = ty->fd_dev_null; 1183 return;
1260#endif
1261 if (fd < 0) return;
1262 if (write(fd, input, len) < 0)
1263 ERR(_("Could not write to file descriptor %d: %s"),
1264 fd, strerror(errno));
1265#endif 1184#endif
1185 int res = ty_sb_add(&ty->write_buffer, input, len);
1186
1187 if (res < 0)
1188 {
1189 ERR("failure to add %d characters to write buffer", len);
1190 }
1191 else
1192 {
1193 ecore_main_fd_handler_active_set(ty->hand_fd,
1194 ECORE_FD_ERROR |
1195 ECORE_FD_READ |
1196 ECORE_FD_WRITE);
1197 }
1266} 1198}
1267 1199
1268struct screen_info 1200struct screen_info
@@ -1365,6 +1297,26 @@ _termpty_line_rewrap(Termpty *ty, Termcell *src_cells, int len,
1365 } 1297 }
1366} 1298}
1367 1299
1300static void
1301_backlog_remove_latest_nolock(Termpty *ty)
1302{
1303 Termsave *ts;
1304 if (ty->backsize == 0)
1305 return;
1306 ts = BACKLOG_ROW_GET(ty, 1);
1307
1308 if (ty->backpos == 0)
1309 ty->backpos = ty->backsize - 1;
1310 else
1311 ty->backpos--;
1312
1313 /* reset beacon */
1314 ty->backlog_beacon.screen_y = 0;
1315 ty->backlog_beacon.backlog_y = 0;
1316
1317 termpty_save_free(ty, ts);
1318}
1319
1368void 1320void
1369termpty_resize(Termpty *ty, int new_w, int new_h) 1321termpty_resize(Termpty *ty, int new_w, int new_h)
1370{ 1322{
@@ -1482,7 +1434,6 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
1482 ty->backlog_beacon.backlog_y = 0; 1434 ty->backlog_beacon.backlog_y = 0;
1483 ty->backlog_beacon.screen_y = 0; 1435 ty->backlog_beacon.screen_y = 0;
1484 1436
1485 verify_beacon(ty, 0);
1486 return; 1437 return;
1487 1438
1488bad: 1439bad:
@@ -1490,32 +1441,6 @@ bad:
1490 free(new_screen); 1441 free(new_screen);
1491} 1442}
1492 1443
1493void
1494termpty_backlog_size_set(Termpty *ty, size_t size)
1495{
1496 if (ty->backsize == size)
1497 return;
1498
1499 /* TODO: RESIZE: handle that case better: changing backscroll size */
1500 termpty_backlog_lock();
1501
1502 if (ty->back)
1503 {
1504 size_t i;
1505
1506 for (i = 0; i < ty->backsize; i++)
1507 termpty_save_free(ty, &ty->back[i]);
1508 free(ty->back);
1509 }
1510 if (size > 0)
1511 ty->back = calloc(1, sizeof(Termsave) * size);
1512 else
1513 ty->back = NULL;
1514 ty->backpos = 0;
1515 ty->backsize = size;
1516 termpty_backlog_unlock();
1517}
1518
1519pid_t 1444pid_t
1520termpty_pid_get(const Termpty *ty) 1445termpty_pid_get(const Termpty *ty)
1521{ 1446{
@@ -1526,11 +1451,17 @@ void
1526termpty_block_free(Termblock *tb) 1451termpty_block_free(Termblock *tb)
1527{ 1452{
1528 char *s; 1453 char *s;
1529 if (tb->path) eina_stringshare_del(tb->path); 1454
1530 if (tb->link) eina_stringshare_del(tb->link); 1455 if (!tb)
1531 if (tb->chid) eina_stringshare_del(tb->chid); 1456 return;
1532 if (tb->obj) evas_object_del(tb->obj); 1457
1533 EINA_LIST_FREE(tb->cmds, s) free(s); 1458 eina_stringshare_del(tb->path);
1459 eina_stringshare_del(tb->link);
1460 eina_stringshare_del(tb->chid);
1461 if (tb->obj)
1462 evas_object_del(tb->obj);
1463 EINA_LIST_FREE(tb->cmds, s)
1464 free(s);
1534 free(tb); 1465 free(tb);
1535} 1466}
1536 1467
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index ef07cb9..faeaa6d 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -13,6 +13,7 @@ typedef struct _Termblock Termblock;
13typedef struct _Termexp Termexp; 13typedef struct _Termexp Termexp;
14typedef struct _Termpty Termpty; 14typedef struct _Termpty Termpty;
15typedef struct _Termlink Term_Link; 15typedef struct _Termlink Term_Link;
16typedef struct _TitleIconElem TitleIconElem;
16 17
17#define COL_DEF 0 18#define COL_DEF 0
18#define COL_BLACK 1 19#define COL_BLACK 1
@@ -81,12 +82,14 @@ struct _Termatt
81 unsigned short fraktur : 1; 82 unsigned short fraktur : 1;
82 unsigned short framed : 1; 83 unsigned short framed : 1;
83 unsigned short encircled : 1; 84 unsigned short encircled : 1;
84 unsigned short overlined : 1; 85 unsigned short overlined : 1; // TODO: support it
86 unsigned short tab_inserted : 1;
87 unsigned short tab_last : 1;
85#if defined(SUPPORT_80_132_COLUMNS) 88#if defined(SUPPORT_80_132_COLUMNS)
86 unsigned short is_80_132_mode_allowed : 1; 89 unsigned short is_80_132_mode_allowed : 1;
87 unsigned short bit_padding : 11; 90 unsigned short bit_padding : 9;
88#else 91#else
89 unsigned short bit_padding : 12; 92 unsigned short bit_padding : 10;
90#endif 93#endif
91 uint16_t link_id; 94 uint16_t link_id;
92}; 95};
@@ -166,12 +169,7 @@ struct _Termpty
166 Backlog_Beacon backlog_beacon; 169 Backlog_Beacon backlog_beacon;
167 int w, h; 170 int w, h;
168 int fd, slavefd; 171 int fd, slavefd;
169#if defined(ENABLE_TESTS)
170 struct ty_sb write_buffer; 172 struct ty_sb write_buffer;
171#endif
172#if defined(ENABLE_FUZZING)
173 int fd_dev_null;
174#endif
175 struct { 173 struct {
176 int curid; 174 int curid;
177 Eina_Hash *blocks; 175 Eina_Hash *blocks;
@@ -210,6 +208,7 @@ struct _Termpty
210 uint8_t *bitmap; 208 uint8_t *bitmap;
211 uint32_t size; 209 uint32_t size;
212 } hl; 210 } hl;
211 TitleIconElem *title_icon_stack;
213}; 212};
214 213
215struct _Termcell 214struct _Termcell
@@ -279,17 +278,12 @@ Termpty *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
279void termpty_free(Termpty *ty); 278void termpty_free(Termpty *ty);
280void termpty_config_update(Termpty *ty, Config *config); 279void termpty_config_update(Termpty *ty, Config *config);
281 280
282void termpty_backlog_lock(void);
283void termpty_backlog_unlock(void);
284
285Termcell *termpty_cellrow_get(Termpty *ty, int y, ssize_t *wret); 281Termcell *termpty_cellrow_get(Termpty *ty, int y, ssize_t *wret);
286Termcell * termpty_cell_get(Termpty *ty, int y_requested, int x_requested); 282Termcell * termpty_cell_get(Termpty *ty, int y_requested, int x_requested);
287ssize_t termpty_row_length(Termpty *ty, int y); 283ssize_t termpty_row_length(Termpty *ty, int y);
288void termpty_write(Termpty *ty, const char *input, int len); 284void termpty_write(Termpty *ty, const char *input, int len);
289void termpty_resize(Termpty *ty, int new_w, int new_h); 285void termpty_resize(Termpty *ty, int new_w, int new_h);
290void termpty_resize_tabs(Termpty *ty, int old_w, int new_w); 286void termpty_resize_tabs(Termpty *ty, int old_w, int new_w);
291void termpty_backlog_size_set(Termpty *ty, size_t size);
292ssize_t termpty_backlog_length(Termpty *ty);
293void termpty_backscroll_adjust(Termpty *ty, int *scroll); 287void termpty_backscroll_adjust(Termpty *ty, int *scroll);
294 288
295pid_t termpty_pid_get(const Termpty *ty); 289pid_t termpty_pid_get(const Termpty *ty);
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index a92b4db..3becfce 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -9,6 +9,7 @@
9#include "termptyesc.h" 9#include "termptyesc.h"
10#include "termptyops.h" 10#include "termptyops.h"
11#include "termptyext.h" 11#include "termptyext.h"
12#include "utils.h"
12#if defined(ENABLE_TESTS) 13#if defined(ENABLE_TESTS)
13#include "tytest.h" 14#include "tytest.h"
14#endif 15#endif
@@ -110,9 +111,9 @@ _cursor_is_within_margins(const Termpty *ty)
110 ); 111 );
111} 112}
112 113
113enum csi_arg_error { 114enum esc_arg_error {
114 CSI_ARG_NO_VALUE = 1, 115 ESC_ARG_NO_VALUE = 1,
115 CSI_ARG_ERROR = 2 116 ESC_ARG_ERROR = 2
116}; 117};
117 118
118static int 119static int
@@ -124,7 +125,7 @@ _csi_arg_get(Termpty *ty, Eina_Unicode **ptr)
124 if ((b == NULL) || (*b == '\0')) 125 if ((b == NULL) || (*b == '\0'))
125 { 126 {
126 *ptr = NULL; 127 *ptr = NULL;
127 return -CSI_ARG_NO_VALUE; 128 return -ESC_ARG_NO_VALUE;
128 } 129 }
129 130
130 /* Skip potential '?', '>'.... */ 131 /* Skip potential '?', '>'.... */
@@ -135,13 +136,13 @@ _csi_arg_get(Termpty *ty, Eina_Unicode **ptr)
135 { 136 {
136 b++; 137 b++;
137 *ptr = b; 138 *ptr = b;
138 return -CSI_ARG_NO_VALUE; 139 return -ESC_ARG_NO_VALUE;
139 } 140 }
140 141
141 if (*b == '\0') 142 if (*b == '\0')
142 { 143 {
143 *ptr = NULL; 144 *ptr = NULL;
144 return -CSI_ARG_NO_VALUE; 145 return -ESC_ARG_NO_VALUE;
145 } 146 }
146 147
147 while ((*b >= '0') && (*b <= '9')) 148 while ((*b >= '0') && (*b <= '9'))
@@ -177,7 +178,7 @@ error:
177 ERR("Invalid CSI argument"); 178 ERR("Invalid CSI argument");
178 ty->decoding_error = EINA_TRUE; 179 ty->decoding_error = EINA_TRUE;
179 *ptr = NULL; 180 *ptr = NULL;
180 return -CSI_ARG_ERROR; 181 return -ESC_ARG_ERROR;
181} 182}
182 183
183static void 184static void
@@ -207,6 +208,8 @@ _cursor_to_start_of_line(Termpty *ty)
207static void 208static void
208_handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) 209_handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
209{ 210{
211 Termcell *cell;
212
210 switch (*cc) 213 switch (*cc)
211 { 214 {
212 case 0x07: // BEL '\a' (bell) 215 case 0x07: // BEL '\a' (bell)
@@ -220,7 +223,11 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
220 return; 223 return;
221 case 0x09: // HT '\t' (horizontal tab) 224 case 0x09: // HT '\t' (horizontal tab)
222 DBG("->HT"); 225 DBG("->HT");
226 cell = &(TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy));
227 cell->att.tab_inserted = 1;
223 _tab_forward(ty, 1); 228 _tab_forward(ty, 1);
229 cell = &(TERMPTY_SCREEN(ty, ty->cursor_state.cx -1, ty->cursor_state.cy));
230 cell->att.tab_last = 1;
224 return; 231 return;
225 case 0x0a: // LF '\n' (new line) 232 case 0x0a: // LF '\n' (new line)
226 case 0x0b: // VT '\v' (vertical tab) 233 case 0x0b: // VT '\v' (vertical tab)
@@ -295,9 +302,9 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b,
295 // http://ttssh2.sourceforge.jp/manual/en/about/ctrlseq.html 302 // http://ttssh2.sourceforge.jp/manual/en/about/ctrlseq.html
296 switch (arg) 303 switch (arg)
297 { 304 {
298 case -CSI_ARG_ERROR: 305 case -ESC_ARG_ERROR:
299 return; 306 return;
300 /* TODO: -CSI_ARG_NO_VALUE */ 307 /* TODO: -ESC_ARG_NO_VALUE */
301 case 1: 308 case 1:
302 ty->termstate.appcursor = mode; 309 ty->termstate.appcursor = mode;
303 break; 310 break;
@@ -547,9 +554,9 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b,
547 554
548 switch (arg) 555 switch (arg)
549 { 556 {
550 case -CSI_ARG_ERROR: 557 case -ESC_ARG_ERROR:
551 return; 558 return;
552 /* TODO: -CSI_ARG_NO_VALUE */ 559 /* TODO: -ESC_ARG_NO_VALUE */
553 case 1: 560 case 1:
554 ty->termstate.appcursor = mode; 561 ty->termstate.appcursor = mode;
555 break; 562 break;
@@ -587,7 +594,7 @@ _csi_truecolor_arg_get(Termpty *ty, Eina_Unicode **ptr)
587 if ((b == NULL) || (*b == '\0')) 594 if ((b == NULL) || (*b == '\0'))
588 { 595 {
589 *ptr = NULL; 596 *ptr = NULL;
590 return -CSI_ARG_NO_VALUE; 597 return -ESC_ARG_NO_VALUE;
591 } 598 }
592 599
593 /* by construction, shall be the same separator as the following ones */ 600 /* by construction, shall be the same separator as the following ones */
@@ -595,26 +602,26 @@ _csi_truecolor_arg_get(Termpty *ty, Eina_Unicode **ptr)
595 if ((separator != ';') && (separator != ':')) 602 if ((separator != ';') && (separator != ':'))
596 { 603 {
597 *ptr = NULL; 604 *ptr = NULL;
598 return -CSI_ARG_NO_VALUE; 605 return -ESC_ARG_NO_VALUE;
599 } 606 }
600 607
601 if (*b == separator) 608 if (*b == separator)
602 { 609 {
603 b++; 610 b++;
604 *ptr = b; 611 *ptr = b;
605 return -CSI_ARG_NO_VALUE; 612 return -ESC_ARG_NO_VALUE;
606 } 613 }
607 614
608 if (*b == '\0') 615 if (*b == '\0')
609 { 616 {
610 *ptr = NULL; 617 *ptr = NULL;
611 return -CSI_ARG_NO_VALUE; 618 return -ESC_ARG_NO_VALUE;
612 } 619 }
613 /* invalid values */ 620 /* invalid values */
614 if ((*b < '0') || (*b > '9')) 621 if ((*b < '0') || (*b > '9'))
615 { 622 {
616 *ptr = NULL; 623 *ptr = NULL;
617 return -CSI_ARG_ERROR; 624 return -ESC_ARG_ERROR;
618 } 625 }
619 626
620 while ((*b >= '0') && (*b <= '9')) 627 while ((*b >= '0') && (*b <= '9'))
@@ -624,7 +631,7 @@ _csi_truecolor_arg_get(Termpty *ty, Eina_Unicode **ptr)
624 *ptr = NULL; 631 *ptr = NULL;
625 ERR("Invalid sequence: argument is too large"); 632 ERR("Invalid sequence: argument is too large");
626 ty->decoding_error = EINA_TRUE; 633 ty->decoding_error = EINA_TRUE;
627 return -CSI_ARG_ERROR; 634 return -ESC_ARG_ERROR;
628 } 635 }
629 sum *= 10; 636 sum *= 10;
630 sum += *b - '0'; 637 sum += *b - '0';
@@ -713,9 +720,9 @@ _handle_esc_csi_truecolor_rgb(Termpty *ty, Eina_Unicode **ptr)
713 r = _csi_truecolor_arg_get(ty, ptr); 720 r = _csi_truecolor_arg_get(ty, ptr);
714 g = _csi_truecolor_arg_get(ty, ptr); 721 g = _csi_truecolor_arg_get(ty, ptr);
715 b = _csi_truecolor_arg_get(ty, ptr); 722 b = _csi_truecolor_arg_get(ty, ptr);
716 if ((r == -CSI_ARG_ERROR) || 723 if ((r == -ESC_ARG_ERROR) ||
717 (g == -CSI_ARG_ERROR) || 724 (g == -ESC_ARG_ERROR) ||
718 (b == -CSI_ARG_ERROR)) 725 (b == -ESC_ARG_ERROR))
719 return COL_DEF; 726 return COL_DEF;
720 727
721 if (separator == ':' && *ptr) 728 if (separator == ':' && *ptr)
@@ -730,7 +737,7 @@ _handle_esc_csi_truecolor_rgb(Termpty *ty, Eina_Unicode **ptr)
730 while ((*ptr) && (**ptr != ';')) 737 while ((*ptr) && (**ptr != ';'))
731 { 738 {
732 int arg = _csi_truecolor_arg_get(ty, ptr); 739 int arg = _csi_truecolor_arg_get(ty, ptr);
733 if (arg == -CSI_ARG_ERROR) 740 if (arg == -ESC_ARG_ERROR)
734 break; 741 break;
735 } 742 }
736 } 743 }
@@ -740,11 +747,11 @@ _handle_esc_csi_truecolor_rgb(Termpty *ty, Eina_Unicode **ptr)
740 } 747 }
741 } 748 }
742 749
743 if (r == -CSI_ARG_NO_VALUE) 750 if (r == -ESC_ARG_NO_VALUE)
744 r = 0; 751 r = 0;
745 if (g == -CSI_ARG_NO_VALUE) 752 if (g == -ESC_ARG_NO_VALUE)
746 g = 0; 753 g = 0;
747 if (b == -CSI_ARG_NO_VALUE) 754 if (b == -ESC_ARG_NO_VALUE)
748 b = 0; 755 b = 0;
749 756
750 return _approximate_truecolor_rgb(ty, r, g, b); 757 return _approximate_truecolor_rgb(ty, r, g, b);
@@ -768,9 +775,9 @@ _handle_esc_csi_truecolor_cmy(Termpty *ty, Eina_Unicode **ptr)
768 m = _csi_truecolor_arg_get(ty, ptr); 775 m = _csi_truecolor_arg_get(ty, ptr);
769 y = _csi_truecolor_arg_get(ty, ptr); 776 y = _csi_truecolor_arg_get(ty, ptr);
770 777
771 if ((c == -CSI_ARG_ERROR) || 778 if ((c == -ESC_ARG_ERROR) ||
772 (m == -CSI_ARG_ERROR) || 779 (m == -ESC_ARG_ERROR) ||
773 (y == -CSI_ARG_ERROR)) 780 (y == -ESC_ARG_ERROR))
774 return COL_DEF; 781 return COL_DEF;
775 782
776 if (separator == ':' && *ptr) 783 if (separator == ':' && *ptr)
@@ -785,7 +792,7 @@ _handle_esc_csi_truecolor_cmy(Termpty *ty, Eina_Unicode **ptr)
785 while ((*ptr) && (**ptr != ';')) 792 while ((*ptr) && (**ptr != ';'))
786 { 793 {
787 int arg = _csi_truecolor_arg_get(ty, ptr); 794 int arg = _csi_truecolor_arg_get(ty, ptr);
788 if (arg == -CSI_ARG_ERROR) 795 if (arg == -ESC_ARG_ERROR)
789 break; 796 break;
790 } 797 }
791 } 798 }
@@ -795,11 +802,11 @@ _handle_esc_csi_truecolor_cmy(Termpty *ty, Eina_Unicode **ptr)
795 } 802 }
796 } 803 }
797 804
798 if (c == -CSI_ARG_NO_VALUE) 805 if (c == -ESC_ARG_NO_VALUE)
799 c = 0; 806 c = 0;
800 if (m == -CSI_ARG_NO_VALUE) 807 if (m == -ESC_ARG_NO_VALUE)
801 m = 0; 808 m = 0;
802 if (y == -CSI_ARG_NO_VALUE) 809 if (y == -ESC_ARG_NO_VALUE)
803 y = 0; 810 y = 0;
804 811
805 r = 255 - ((c * 255) / 100); 812 r = 255 - ((c * 255) / 100);
@@ -828,10 +835,10 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
828 y = _csi_truecolor_arg_get(ty, ptr); 835 y = _csi_truecolor_arg_get(ty, ptr);
829 k = _csi_truecolor_arg_get(ty, ptr); 836 k = _csi_truecolor_arg_get(ty, ptr);
830 837
831 if ((c == -CSI_ARG_ERROR) || 838 if ((c == -ESC_ARG_ERROR) ||
832 (m == -CSI_ARG_ERROR) || 839 (m == -ESC_ARG_ERROR) ||
833 (y == -CSI_ARG_ERROR) || 840 (y == -ESC_ARG_ERROR) ||
834 (k == -CSI_ARG_ERROR)) 841 (k == -ESC_ARG_ERROR))
835 return COL_DEF; 842 return COL_DEF;
836 843
837 if (separator == ':' && *ptr) 844 if (separator == ':' && *ptr)
@@ -847,7 +854,7 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
847 while ((*ptr) && (**ptr != ';')) 854 while ((*ptr) && (**ptr != ';'))
848 { 855 {
849 int arg = _csi_truecolor_arg_get(ty, ptr); 856 int arg = _csi_truecolor_arg_get(ty, ptr);
850 if (arg == -CSI_ARG_ERROR) 857 if (arg == -ESC_ARG_ERROR)
851 break; 858 break;
852 } 859 }
853 } 860 }
@@ -857,13 +864,13 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
857 } 864 }
858 } 865 }
859 866
860 if (c == -CSI_ARG_NO_VALUE) 867 if (c == -ESC_ARG_NO_VALUE)
861 c = 0; 868 c = 0;
862 if (m == -CSI_ARG_NO_VALUE) 869 if (m == -ESC_ARG_NO_VALUE)
863 m = 0; 870 m = 0;
864 if (y == -CSI_ARG_NO_VALUE) 871 if (y == -ESC_ARG_NO_VALUE)
865 y = 0; 872 y = 0;
866 if (k == -CSI_ARG_NO_VALUE) 873 if (k == -ESC_ARG_NO_VALUE)
867 k = 0; 874 k = 0;
868 875
869 r = (255 * (100 - c) * (100 - k)) / 100 / 100; 876 r = (255 * (100 - c) * (100 - k)) / 100 / 100;
@@ -891,9 +898,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
891 int arg = _csi_arg_get(ty, &b); 898 int arg = _csi_arg_get(ty, &b);
892 switch (arg) 899 switch (arg)
893 { 900 {
894 case -CSI_ARG_ERROR: 901 case -ESC_ARG_ERROR:
895 return; 902 return;
896 case -CSI_ARG_NO_VALUE: 903 case -ESC_ARG_NO_VALUE:
897 EINA_FALLTHROUGH; 904 EINA_FALLTHROUGH;
898 case 0: // reset to normal 905 case 0: // reset to normal
899 termpty_reset_att(&(ty->termstate.att)); 906 termpty_reset_att(&(ty->termstate.att));
@@ -971,9 +978,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
971 arg = _csi_arg_get(ty, &b); 978 arg = _csi_arg_get(ty, &b);
972 switch (arg) 979 switch (arg)
973 { 980 {
974 case -CSI_ARG_ERROR: 981 case -ESC_ARG_ERROR:
975 return; 982 return;
976 /* TODO: -CSI_ARG_NO_VALUE */ 983 /* TODO: -ESC_ARG_NO_VALUE */
977 case 1: 984 case 1:
978 ty->termstate.att.fg256 = 0; 985 ty->termstate.att.fg256 = 0;
979 ty->termstate.att.fg = COL_INVIS; 986 ty->termstate.att.fg = COL_INVIS;
@@ -1002,14 +1009,14 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
1002 case 5: 1009 case 5:
1003 // then get next arg - should be color index 0-255 1010 // then get next arg - should be color index 0-255
1004 arg = _csi_arg_get(ty, &b); 1011 arg = _csi_arg_get(ty, &b);
1005 if (arg <= -CSI_ARG_ERROR || arg > 255) 1012 if (arg <= -ESC_ARG_ERROR || arg > 255)
1006 { 1013 {
1007 ERR("Invalid fg color %d", arg); 1014 ERR("Invalid fg color %d", arg);
1008 ty->decoding_error = EINA_TRUE; 1015 ty->decoding_error = EINA_TRUE;
1009 } 1016 }
1010 else 1017 else
1011 { 1018 {
1012 if (arg == -CSI_ARG_NO_VALUE) 1019 if (arg == -ESC_ARG_NO_VALUE)
1013 arg = 0; 1020 arg = 0;
1014 ty->termstate.att.fg256 = 1; 1021 ty->termstate.att.fg256 = 1;
1015 ty->termstate.att.fg = arg; 1022 ty->termstate.att.fg = arg;
@@ -1042,9 +1049,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
1042 arg = _csi_arg_get(ty, &b); 1049 arg = _csi_arg_get(ty, &b);
1043 switch (arg) 1050 switch (arg)
1044 { 1051 {
1045 case -CSI_ARG_ERROR: 1052 case -ESC_ARG_ERROR:
1046 return; 1053 return;
1047 /* TODO: -CSI_ARG_NO_VALUE */ 1054 /* TODO: -ESC_ARG_NO_VALUE */
1048 case 1: 1055 case 1:
1049 ty->termstate.att.bg256 = 0; 1056 ty->termstate.att.bg256 = 0;
1050 ty->termstate.att.bg = COL_INVIS; 1057 ty->termstate.att.bg = COL_INVIS;
@@ -1073,14 +1080,14 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
1073 case 5: 1080 case 5:
1074 // then get next arg - should be color index 0-255 1081 // then get next arg - should be color index 0-255
1075 arg = _csi_arg_get(ty, &b); 1082 arg = _csi_arg_get(ty, &b);
1076 if (arg <= -CSI_ARG_ERROR || arg > 255) 1083 if (arg <= -ESC_ARG_ERROR || arg > 255)
1077 { 1084 {
1078 ERR("Invalid bg color %d", arg); 1085 ERR("Invalid bg color %d", arg);
1079 ty->decoding_error = EINA_TRUE; 1086 ty->decoding_error = EINA_TRUE;
1080 } 1087 }
1081 else 1088 else
1082 { 1089 {
1083 if (arg == -CSI_ARG_NO_VALUE) 1090 if (arg == -ESC_ARG_NO_VALUE)
1084 arg = 0; 1091 arg = 0;
1085 ty->termstate.att.bg256 = 1; 1092 ty->termstate.att.bg256 = 1;
1086 ty->termstate.att.bg = arg; 1093 ty->termstate.att.bg = arg;
@@ -1164,7 +1171,7 @@ _handle_esc_csi_cnl(Termpty *ty, Eina_Unicode **ptr)
1164 int arg = _csi_arg_get(ty, &b); 1171 int arg = _csi_arg_get(ty, &b);
1165 int max = ty->h; 1172 int max = ty->h;
1166 1173
1167 if (arg == -CSI_ARG_ERROR) 1174 if (arg == -ESC_ARG_ERROR)
1168 return; 1175 return;
1169 if (arg < 1) 1176 if (arg < 1)
1170 arg = 1; 1177 arg = 1;
@@ -1189,7 +1196,7 @@ _handle_esc_csi_cpl(Termpty *ty, Eina_Unicode **ptr)
1189 int arg = _csi_arg_get(ty, &b); 1196 int arg = _csi_arg_get(ty, &b);
1190 int max = ty->h; 1197 int max = ty->h;
1191 1198
1192 if (arg == -CSI_ARG_ERROR) 1199 if (arg == -ESC_ARG_ERROR)
1193 return; 1200 return;
1194 if (arg < 1) 1201 if (arg < 1)
1195 arg = 1; 1202 arg = 1;
@@ -1215,7 +1222,7 @@ _handle_esc_csi_dch(Termpty *ty, Eina_Unicode **ptr)
1215 Termcell *cells; 1222 Termcell *cells;
1216 int x, lim, max; 1223 int x, lim, max;
1217 1224
1218 if (arg == -CSI_ARG_ERROR) 1225 if (arg == -ESC_ARG_ERROR)
1219 return; 1226 return;
1220 1227
1221 DBG("DCH - Delete Character: %d chars", arg); 1228 DBG("DCH - Delete Character: %d chars", arg);
@@ -1273,7 +1280,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
1273 arg = _csi_arg_get(ty, &b); 1280 arg = _csi_arg_get(ty, &b);
1274 switch (arg) 1281 switch (arg)
1275 { 1282 {
1276 case -CSI_ARG_ERROR: 1283 case -ESC_ARG_ERROR:
1277 return; 1284 return;
1278 case 5: 1285 case 5:
1279 if (question_mark) 1286 if (question_mark)
@@ -1382,7 +1389,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
1382 { 1389 {
1383 /* DSR-DECCKSR (Memory Checksum) */ 1390 /* DSR-DECCKSR (Memory Checksum) */
1384 int pid = _csi_arg_get(ty, &b); 1391 int pid = _csi_arg_get(ty, &b);
1385 if (pid == -CSI_ARG_NO_VALUE) 1392 if (pid == -ESC_ARG_NO_VALUE)
1386 pid = 65535; 1393 pid = 65535;
1387 len = snprintf(bf, sizeof(bf), "\033P%u!~0000\033\\", 1394 len = snprintf(bf, sizeof(bf), "\033P%u!~0000\033\\",
1388 ((unsigned int)pid) % 65536); 1395 ((unsigned int)pid) % 65536);
@@ -1408,7 +1415,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
1408 ty->decoding_error = EINA_TRUE; 1415 ty->decoding_error = EINA_TRUE;
1409 } 1416 }
1410 break; 1417 break;
1411 /* TODO: -CSI_ARG_NO_VALUE */ 1418 /* TODO: -ESC_ARG_NO_VALUE */
1412 default: 1419 default:
1413 WRN("unhandled DSR (dec specific: %s) %d", 1420 WRN("unhandled DSR (dec specific: %s) %d",
1414 (question_mark)? "yes": "no", arg); 1421 (question_mark)? "yes": "no", arg);
@@ -1424,7 +1431,7 @@ _handle_esc_csi_decslrm(Termpty *ty, Eina_Unicode **b)
1424 int right = _csi_arg_get(ty, b); 1431 int right = _csi_arg_get(ty, b);
1425 1432
1426 DBG("DECSLRM (%d;%d) Set Left and Right Margins", left, right); 1433 DBG("DECSLRM (%d;%d) Set Left and Right Margins", left, right);
1427 if ((left == -CSI_ARG_ERROR) || (right == -CSI_ARG_ERROR)) 1434 if ((left == -ESC_ARG_ERROR) || (right == -ESC_ARG_ERROR))
1428 goto bad; 1435 goto bad;
1429 1436
1430 TERMPTY_RESTRICT_FIELD(left, 1, ty->w); 1437 TERMPTY_RESTRICT_FIELD(left, 1, ty->w);
@@ -1458,7 +1465,7 @@ _handle_esc_csi_decstbm(Termpty *ty, Eina_Unicode **b)
1458 int bottom = _csi_arg_get(ty, b); 1465 int bottom = _csi_arg_get(ty, b);
1459 1466
1460 DBG("DECSTBM (%d;%d) Set Top and Bottom Margins", top, bottom); 1467 DBG("DECSTBM (%d;%d) Set Top and Bottom Margins", top, bottom);
1461 if ((top == -CSI_ARG_ERROR) || (bottom == -CSI_ARG_ERROR)) 1468 if ((top == -ESC_ARG_ERROR) || (bottom == -ESC_ARG_ERROR))
1462 goto bad; 1469 goto bad;
1463 1470
1464 TERMPTY_RESTRICT_FIELD(top, 1, ty->h); 1471 TERMPTY_RESTRICT_FIELD(top, 1, ty->h);
@@ -1631,12 +1638,12 @@ _handle_esc_csi_decfra(Termpty *ty, Eina_Unicode **b)
1631 1638
1632 DBG("DECFRA (%d; %d;%d;%d;%d) Fill Rectangular Area", 1639 DBG("DECFRA (%d; %d;%d;%d;%d) Fill Rectangular Area",
1633 c, top, left, bottom, right); 1640 c, top, left, bottom, right);
1634 if ((c == -CSI_ARG_ERROR) || 1641 if ((c == -ESC_ARG_ERROR) ||
1635 (c == -CSI_ARG_NO_VALUE) || 1642 (c == -ESC_ARG_NO_VALUE) ||
1636 (top == -CSI_ARG_ERROR) || 1643 (top == -ESC_ARG_ERROR) ||
1637 (left == -CSI_ARG_ERROR) || 1644 (left == -ESC_ARG_ERROR) ||
1638 (bottom == -CSI_ARG_ERROR) || 1645 (bottom == -ESC_ARG_ERROR) ||
1639 (right == -CSI_ARG_ERROR)) 1646 (right == -ESC_ARG_ERROR))
1640 return; 1647 return;
1641 1648
1642 if (! ((c >= 32 && c <= 126) || (c >= 160 && c <= 255))) 1649 if (! ((c >= 32 && c <= 126) || (c >= 160 && c <= 255)))
@@ -1708,10 +1715,10 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
1708 1715
1709 DBG("DECCARA (%d;%d;%d;%d) Change Attributes in Rectangular Area", 1716 DBG("DECCARA (%d;%d;%d;%d) Change Attributes in Rectangular Area",
1710 top, left, bottom, right); 1717 top, left, bottom, right);
1711 if ((top == -CSI_ARG_ERROR) || 1718 if ((top == -ESC_ARG_ERROR) ||
1712 (left == -CSI_ARG_ERROR) || 1719 (left == -ESC_ARG_ERROR) ||
1713 (bottom == -CSI_ARG_ERROR) || 1720 (bottom == -ESC_ARG_ERROR) ||
1714 (right == -CSI_ARG_ERROR)) 1721 (right == -ESC_ARG_ERROR))
1715 return; 1722 return;
1716 1723
1717 while (b && b < end) 1724 while (b && b < end)
@@ -1719,9 +1726,9 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
1719 int arg = _csi_arg_get(ty, &b); 1726 int arg = _csi_arg_get(ty, &b);
1720 switch (arg) 1727 switch (arg)
1721 { 1728 {
1722 case -CSI_ARG_ERROR: 1729 case -ESC_ARG_ERROR:
1723 return; 1730 return;
1724 case -CSI_ARG_NO_VALUE: 1731 case -ESC_ARG_NO_VALUE:
1725 EINA_FALLTHROUGH; 1732 EINA_FALLTHROUGH;
1726 case 0: 1733 case 0:
1727 set_bold = set_underline = set_blink = set_inverse = EINA_FALSE; 1734 set_bold = set_underline = set_blink = set_inverse = EINA_FALSE;
@@ -1876,10 +1883,10 @@ _handle_esc_csi_decrara(Termpty *ty, Eina_Unicode **ptr,
1876 1883
1877 DBG("DECRARA (%d;%d;%d;%d) Reverse Attributes in Rectangular Area", 1884 DBG("DECRARA (%d;%d;%d;%d) Reverse Attributes in Rectangular Area",
1878 top, left, bottom, right); 1885 top, left, bottom, right);
1879 if ((top == -CSI_ARG_ERROR) || 1886 if ((top == -ESC_ARG_ERROR) ||
1880 (left == -CSI_ARG_ERROR) || 1887 (left == -ESC_ARG_ERROR) ||
1881 (bottom == -CSI_ARG_ERROR) || 1888 (bottom == -ESC_ARG_ERROR) ||
1882 (right == -CSI_ARG_ERROR)) 1889 (right == -ESC_ARG_ERROR))
1883 return; 1890 return;
1884 1891
1885 while (b && b < end) 1892 while (b && b < end)
@@ -1887,9 +1894,9 @@ _handle_esc_csi_decrara(Termpty *ty, Eina_Unicode **ptr,
1887 int arg = _csi_arg_get(ty, &b); 1894 int arg = _csi_arg_get(ty, &b);
1888 switch (arg) 1895 switch (arg)
1889 { 1896 {
1890 case -CSI_ARG_ERROR: 1897 case -ESC_ARG_ERROR:
1891 return; 1898 return;
1892 case -CSI_ARG_NO_VALUE: 1899 case -ESC_ARG_NO_VALUE:
1893 EINA_FALLTHROUGH; 1900 EINA_FALLTHROUGH;
1894 case 0: 1901 case 0:
1895 reverse_bold = reverse_underline = reverse_blink = reverse_inverse = EINA_TRUE; 1902 reverse_bold = reverse_underline = reverse_blink = reverse_inverse = EINA_TRUE;
@@ -1980,10 +1987,10 @@ _handle_esc_csi_decera(Termpty *ty, Eina_Unicode **b)
1980 DBG("DECERA (%d;%d;%d;%d) Erase Rectangular Area", 1987 DBG("DECERA (%d;%d;%d;%d) Erase Rectangular Area",
1981 top, left, bottom, right); 1988 top, left, bottom, right);
1982 1989
1983 if ((top == -CSI_ARG_ERROR) || 1990 if ((top == -ESC_ARG_ERROR) ||
1984 (left == -CSI_ARG_ERROR) || 1991 (left == -ESC_ARG_ERROR) ||
1985 (bottom == -CSI_ARG_ERROR) || 1992 (bottom == -ESC_ARG_ERROR) ||
1986 (right == -CSI_ARG_ERROR)) 1993 (right == -ESC_ARG_ERROR))
1987 return; 1994 return;
1988 1995
1989 if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0) 1996 if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
@@ -2014,14 +2021,14 @@ _handle_esc_csi_deccra(Termpty *ty, Eina_Unicode **b)
2014 2021
2015 DBG("DECFRA (%d;%d;%d;%d -> %d;%d) Copy Rectangular Area", 2022 DBG("DECFRA (%d;%d;%d;%d -> %d;%d) Copy Rectangular Area",
2016 top, left, bottom, right, to_top, to_left); 2023 top, left, bottom, right, to_top, to_left);
2017 if ((top == -CSI_ARG_ERROR) || 2024 if ((top == -ESC_ARG_ERROR) ||
2018 (left == -CSI_ARG_ERROR) || 2025 (left == -ESC_ARG_ERROR) ||
2019 (bottom == -CSI_ARG_ERROR) || 2026 (bottom == -ESC_ARG_ERROR) ||
2020 (right == -CSI_ARG_ERROR) || 2027 (right == -ESC_ARG_ERROR) ||
2021 (p1 == -CSI_ARG_ERROR) || 2028 (p1 == -ESC_ARG_ERROR) ||
2022 (to_top == -CSI_ARG_ERROR) || 2029 (to_top == -ESC_ARG_ERROR) ||
2023 (to_left == -CSI_ARG_ERROR) || 2030 (to_left == -ESC_ARG_ERROR) ||
2024 (p2 == -CSI_ARG_ERROR)) 2031 (p2 == -ESC_ARG_ERROR))
2025 return; 2032 return;
2026 2033
2027 if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0) 2034 if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
@@ -2131,7 +2138,7 @@ _handle_esc_csi_cursor_pos_set(Termpty *ty, Eina_Unicode **b,
2131 cy = _csi_arg_get(ty, b); 2138 cy = _csi_arg_get(ty, b);
2132 cx = _csi_arg_get(ty, b); 2139 cx = _csi_arg_get(ty, b);
2133 2140
2134 if ((cx == -CSI_ARG_ERROR) || (cy == -CSI_ARG_ERROR)) 2141 if ((cx == -ESC_ARG_ERROR) || (cy == -ESC_ARG_ERROR))
2135 return; 2142 return;
2136 2143
2137 DBG("cursor pos set (%s) (%d;%d)", (*cc == 'H') ? "CUP" : "HVP", 2144 DBG("cursor pos set (%s) (%d;%d)", (*cc == 'H') ? "CUP" : "HVP",
@@ -2174,9 +2181,9 @@ _handle_esc_csi_decscusr(Termpty *ty, Eina_Unicode **b)
2174 2181
2175 switch (arg) 2182 switch (arg)
2176 { 2183 {
2177 case -CSI