summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-08-23 02:27:54 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-08-23 02:27:54 +0000
commit3aa2288a07d0922c5c7f3c1a0b53c6f097d670ef (patch)
tree806daa5de1c5b41cff358f9d05ca40c760299f37 /src
parent0accdc7ef596751101d040863927f647cf0b3df8 (diff)
refactor cmd in separate functions, it's growing too big.
SVN revision: 75583
Diffstat (limited to 'src')
-rw-r--r--src/bin/termcmd.c214
1 files changed, 109 insertions, 105 deletions
diff --git a/src/bin/termcmd.c b/src/bin/termcmd.c
index 97c7952..fb64014 100644
--- a/src/bin/termcmd.c
+++ b/src/bin/termcmd.c
@@ -10,134 +10,138 @@
10#include "utils.h" 10#include "utils.h"
11#include "termcmd.h" 11#include "termcmd.h"
12 12
13// called as u type 13static Eina_Bool
14Eina_Bool 14_termcmd_search(Evas_Object *obj __UNUSED__, Evas_Object *win __UNUSED__, Evas_Object *bg __UNUSED__, const char *cmd)
15termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
16{ 15{
17 if (!cmd) return EINA_FALSE; 16 if (cmd[0] == 0) // clear search
18 if ((cmd[0] == '/') || (cmd[0] == 's')) // search
19 { 17 {
20 if (cmd[1] == 0) // clear search 18 printf("search clear\n");
21 {
22 printf("search clear\n");
23 return EINA_TRUE;
24 }
25 printf("search '%s'\n", cmd + 1);
26 return EINA_TRUE; 19 return EINA_TRUE;
27 } 20 }
28 return EINA_FALSE; 21 printf("search '%s'\n", cmd);
29 obj = win = bg = NULL; 22 return EINA_TRUE;
30} 23}
31 24
32// called when you hit enter 25static Eina_Bool
33Eina_Bool 26_termcmd_font_size(Evas_Object *obj, Evas_Object *win __UNUSED__, Evas_Object *bg __UNUSED__, const char *cmd)
34termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
35{ 27{
36 if (!cmd) return EINA_FALSE; 28 Config *config = termio_config_get(obj);
37 if ((cmd[0] == '/') || (cmd[0] == 's')) // search 29
30 if (config)
38 { 31 {
39 if (cmd[1] == 0) // clear search 32 if (cmd[0] == 0) // back to default
40 { 33 {
41 printf("search clear\n"); 34 config->font.bitmap = config->font.orig_bitmap;
35 if (config->font.orig_name)
36 {
37 eina_stringshare_del(config->font.name);
38 config->font.name = eina_stringshare_add(config->font.orig_name);
39 }
40 termio_font_size_set(obj, config->font.orig_size);
42 return EINA_TRUE; 41 return EINA_TRUE;
43 } 42 }
44 printf("search '%s'\n", cmd + 1); 43 else if (cmd[0] == 'b') // big font size
45 return EINA_TRUE;
46 }
47 if ((cmd[0] == 'f') || (cmd[0] == 'F')) // font size
48 {
49 Config *config = termio_config_get(obj);
50
51 if (config)
52 { 44 {
53 if (cmd[1] == 0) // back to default 45 if (config->font.orig_bitmap)
54 { 46 {
55 config->font.bitmap = config->font.orig_bitmap; 47 config->font.bitmap = 1;
56 if (config->font.orig_name) 48 eina_stringshare_del(config->font.name);
57 { 49 config->font.name = eina_stringshare_add("10x20.pcf");
58 eina_stringshare_del(config->font.name); 50 termio_font_size_set(obj, 20);
59 config->font.name = eina_stringshare_add(config->font.orig_name);
60 }
61 termio_font_size_set(obj, config->font.orig_size);
62 return EINA_TRUE;
63 } 51 }
64 else if (cmd[1] == 'b') // big font size 52 else
65 { 53 {
66 if (config->font.orig_bitmap) 54 termio_font_size_set(obj, 20);
67 {
68 config->font.bitmap = 1;
69 eina_stringshare_del(config->font.name);
70 config->font.name = eina_stringshare_add("10x20.pcf");
71 termio_font_size_set(obj, 20);
72 }
73 else
74 {
75 termio_font_size_set(obj, 20);
76 }
77 }
78 else if (cmd[1] == '+') // size up
79 {
80 termio_font_size_set(obj, config->font.size + 1);
81 }
82 else if (cmd[1] == '-') // size down
83 {
84 termio_font_size_set(obj, config->font.size - 1);
85 } 55 }
86 } 56 }
87 return EINA_TRUE; 57 else if (cmd[0] == '+') // size up
58 {
59 termio_font_size_set(obj, config->font.size + 1);
60 }
61 else if (cmd[0] == '-') // size down
62 {
63 termio_font_size_set(obj, config->font.size - 1);
64 }
88 } 65 }
89 if ((cmd[0] == 'g') || (cmd[0] == 'G')) // grid size 66 return EINA_TRUE;
90 { 67}
91 int w = -1, h = -1;
92 int r = sscanf(cmd, "g%ix%i", &w, &h);
93 68
94 if (r == 1) 69static Eina_Bool
70_termcmd_grid_size(Evas_Object *obj, Evas_Object *win __UNUSED__, Evas_Object *bg __UNUSED__, const char *cmd)
71{
72 int w = -1, h = -1;
73 int r = sscanf(cmd, "%ix%i", &w, &h);
74
75 if (r == 1)
76 {
77 switch (w)
95 { 78 {
96 switch (w) 79 case 0:
97 { 80 w = 80;
98 case 0: 81 h = 24;
99 w = 80; 82 break;
100 h = 24; 83 case 1:
101 break; 84 w = 80;
102 case 1: 85 h = 40;
103 w = 80; 86 break;
104 h = 40; 87 case 2:
105 break; 88 w = 80;
106 case 2: 89 h = 60;
107 w = 80; 90 break;
108 h = 60; 91 case 3:
109 break; 92 w = 80;
110 case 3: 93 h = 80;
111 w = 80; 94 break;
112 h = 80; 95 case 4:
113 break; 96 w = 120;
114 case 4: 97 h = 24;
115 w = 120; 98 break;
116 h = 24; 99 case 5:
117 break; 100 w = 120;
118 case 5: 101 h = 40;
119 w = 120; 102 break;
120 h = 40; 103 case 6:
121 break; 104 w = 120;
122 case 6: 105 h = 60;
123 w = 120; 106 break;
124 h = 60; 107 case 7:
125 break; 108 w = 120;
126 case 7: 109 h = 80;
127 w = 120; 110 break;
128 h = 80; 111 case 8:
129 break; 112 w = 120;
130 case 8: 113 h = 120;
131 w = 120; 114 break;
132 h = 120;
133 break;
134 }
135 } 115 }
136 if ((w > 0) && (h > 0))
137 termio_grid_size_set(obj, w, h);
138 return EINA_TRUE;
139 } 116 }
117 if ((w > 0) && (h > 0))
118 termio_grid_size_set(obj, w, h);
119 return EINA_TRUE;
120}
121
122// called as u type
123Eina_Bool
124termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
125{
126 if (!cmd) return EINA_FALSE;
127 if ((cmd[0] == '/') || (cmd[0] == 's'))
128 return _termcmd_search(obj, win, bg, cmd + 1);
140 return EINA_FALSE; 129 return EINA_FALSE;
141 obj = win = bg = NULL; 130 obj = win = bg = NULL;
142} 131}
143 132
133// called when you hit enter
134Eina_Bool
135termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
136{
137 if (!cmd) return EINA_FALSE;
138 if ((cmd[0] == '/') || (cmd[0] == 's'))
139 return _termcmd_search(obj, win, bg, cmd + 1);
140 if ((cmd[0] == 'f') || (cmd[0] == 'F'))
141 return _termcmd_font_size(obj, win, bg, cmd + 1);
142 if ((cmd[0] == 'g') || (cmd[0] == 'G'))
143 return _termcmd_grid_size(obj, win, bg, cmd + 1);
144
145 return EINA_FALSE;
146 obj = win = bg = NULL;
147}