void main() // Main function { badge_setup(); // Call badge setup oledprint("BUTTONS"); // Large display heading text_size(SMALL); // Switch to small text cursor(0, 4); // Small cursor row 4 oledprint("PAD: 6543210"); // Display bit index cursor(0, 5); // Next line oledprint("STATE:"); // Display state cursor(0, 7); // Next line oledprint("EXIT: Press OSH"); // User prompt to exit while(1) // States loop { states = buttons(); // Load buttons output to states leds(states); // Light up corresponding LEDs cursor(7, 5); // Position cursor oledprint("%07b", states); // Display states as binary number if(states == 0b1000000) break; // If OSH pressed, exit loop } pause(400); // Wait for 4/10 s text_size(LARGE); // Large text clear(); // Clear display oledprint("ALL DONE"); // Done message }
gfx::Rect Label::GetTextBounds() const { gfx::Rect available_rect(GetAvailableRect()); gfx::Size text_size(GetTextSize()); text_size.set_width(std::min(available_rect.width(), text_size.width())); gfx::Insets insets = GetInsets(); gfx::Point text_origin(insets.left(), insets.top()); switch(horiz_alignment_) { case ALIGN_LEFT: break; case ALIGN_CENTER: // We put any extra margin pixel on the left rather than the right. We // used to do this because measurement on Windows used // GetTextExtentPoint32(), which could report a value one too large on the // right; we now use DrawText(), and who knows if it can also do this. text_origin.Offset((available_rect.width()+1-text_size.width())/2, 0); break; case ALIGN_RIGHT: text_origin.set_x(available_rect.right()-text_size.width()); break; default: NOTREACHED(); break; } text_origin.Offset(0, std::max(0, (available_rect.height()-text_size.height()))/2); return gfx::Rect(text_origin, text_size); }
Win *window_new_file(Vis *vis, File *file) { Win *win = calloc(1, sizeof(Win)); if (!win) return NULL; win->vis = vis; win->file = file; win->jumplist = ringbuf_alloc(31); win->view = view_new(file->text, vis->lua); win->ui = vis->ui->window_new(vis->ui, win->view, file, UI_OPTION_STATUSBAR); if (!win->jumplist || !win->view || !win->ui) { window_free(win); return NULL; } file->refcount++; view_tabwidth_set(win->view, vis->tabwidth); if (text_size(file->text) > LARGE_FILE) { enum UiOption opt = view_options_get(win->view); opt |= UI_OPTION_LARGE_FILE; opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; view_options_set(win->view, opt); } if (vis->windows) vis->windows->prev = win; win->next = vis->windows; vis->windows = win; vis->win = win; vis->ui->window_focus(win->ui); for (size_t i = 0; i < LENGTH(win->modes); i++) win->modes[i].parent = &vis_modes[i]; if (vis->event && vis->event->win_open) vis->event->win_open(vis, win); return win; }
static void br_opengl_draw_tooltip(duc_graph *g, double x, double y, char *text) { struct opengl_backend_data *bd = g->backend_data; double w, h; text_size(g, text, &w, &h, FONT_SIZE_TOOLTIP); GLfloat vVertices[] = { x - g->cx - w - 10, y - g->cy - h - 15, x - g->cx , y - g->cy - h - 15, x - g->cx , y - g->cy , x - g->cx - w - 10, y - g->cy , }; glVertexAttribPointer(bd->loc_pos, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), &vVertices[0]); glDisableVertexAttribArray(bd->loc_color); glDisableVertexAttribArray(bd->loc_texture); glVertexAttrib4f(bd->loc_color, 1, 1, 1, 0); GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); glVertexAttrib4f(bd->loc_color, 0, 0, 0, 0); glDrawArrays(GL_LINE_LOOP, 0, 4); draw_text(g, x - w - 5, y - h - 5, FONT_SIZE_TOOLTIP, text); }
//__attribute__((constructor)) int32_t badge_setup(void) { printf("Start\n"); touch_start(TPCount, TPPins, TPDischarge); if(!eei2cLockFlag) { printf("1\n"); eei2cLock = locknew(); lockclr(eei2cLock); eei2cLockFlag = 1; printf("1\n"); } init_MMA7660FC(); printf("1\n"); if(!st_eeInitFlag) ee_init(); printf("1\n"); cpcog = light_start(); printf("1\n"); cogIRcom = ircom_start(IR_IN, IR_OUT, 2400, 38500); printf("1\n"); screen_init(OLED_CS, OLED_DC, OLED_DAT, OLED_CLK, OLED_RST, SSD1306_SWITCHCAPVCC, TYPE_128X64); printf("1\n"); screen_auto(ON); printf("1\n"); clear(); printf("1\n"); text_size(LARGE); printf("Return\n"); return 0; }
/* Allocate new text window */ TW * text_new(void) { TW *tw; tw = (TW *)malloc(sizeof(TW)); if (tw == NULL) return NULL; /* make sure everything is null */ memset(tw, 0, sizeof(TW)); /* set some defaults */ text_font(tw, "Courier New", 10); text_size(tw, 80, 24); tw->KeyBufSize = 2048; tw->CursorFlag = 1; /* scroll to cursor after \n or \r */ tw->hwnd = HWND_DESKTOP; tw->line_end = 0; tw->line_start = 0; tw->line_complete = FALSE; tw->line_eof = FALSE; tw->x = CW_USEDEFAULT; tw->y = CW_USEDEFAULT; tw->cx = CW_USEDEFAULT; tw->cy = CW_USEDEFAULT; #ifndef WINDOWS_NO_UNICODE tw->utf8shift = 0; #endif return tw; }
/* move the cursor to the character at pos bytes from the begining of the file. * if pos is not in the current viewport, redraw the view to make it visible */ void view_cursor_to(View *view, size_t pos) { size_t max = text_size(view->text); if (pos > max) pos = max > 0 ? max - 1 : 0; if (pos == max && view->end != max) { /* do not display an empty screen when shoviewg the end of the file */ view->start = max - 1; view_viewport_up(view, view->height / 2); } else { /* set the start of the viewable region to the start of the line on which * the cursor should be placed. if this line requires more space than * available in the view then simply start displaying text at the new * cursor position */ for (int i = 0; i < 2 && (pos < view->start || pos > view->end); i++) { view->start = i == 0 ? text_line_begin(view->text, pos) : pos; view_draw(view); } } view->cursor.pos = pos; view_cursor_sync(view); view_cursor_update(view); }
// Set up some global things void Init(void) { screen_auto(0); // Set the screen not to auto-update (we want to control it) text_size(SMALL); // Set the text size UsedShots = 0; // No shots currently active FreeShots = MaxShots; }
void Canvas::text_clipped(int x, int y, unsigned width, const TCHAR *text) { const SIZE size = text_size(text); RECT rc; ::SetRect(&rc, x, y, x + min(width, (unsigned)size.cx), y + size.cy); text_clipped(x, y, rc, text); }
static size_t op_delete(Vis *vis, Text *txt, OperatorContext *c) { c->reg->linewise = c->linewise; register_put_range(vis, c->reg, txt, &c->range); text_delete_range(txt, &c->range); size_t pos = c->range.start; if (c->linewise && pos == text_size(txt)) pos = text_line_begin(txt, text_line_prev(txt, pos)); return pos; }
Filerange text_object_search_forward(Text *txt, size_t pos, Regex *regex) { size_t start = pos; size_t end = text_size(txt); RegexMatch match[1]; bool found = start < end && !text_search_range_forward(txt, start, end - start, regex, 1, match, 0); if (found) return text_range_new(match[0].start, match[0].end); return text_range_empty(); }
void Fl_Input_Browser::preferred_size(int& w, int& h) const { fl_font(text_font(), float(text_size())); h = int(fl_height()+fl_descent()) + box()->dh() + 2; if(m_input.maximum_size()>0) { int ms = m_input.maximum_size() + 1; if (ms > 50) ms = 50; w = ms * (int)fl_width((unsigned int)'W') + h; } }
const SIZE Canvas::text_size(const TCHAR *text, size_t length) const { TCHAR *duplicated = _tcsdup(text); duplicated[length] = 0; const SIZE size = text_size(duplicated); free(duplicated); return size; }
static void vis_args(Vis *vis, int argc, char *argv[]) { char *cmd = NULL; bool end_of_options = false; for (int i = 1; i < argc; i++) { if (argv[i][0] == '-' && !end_of_options) { switch (argv[i][1]) { case '-': end_of_options = true; break; case 'v': vis_die(vis, "vis %s\n", VERSION); break; case '\0': break; default: vis_die(vis, "Unknown command option: %s\n", argv[i]); break; } } else if (argv[i][0] == '+') { cmd = argv[i] + (argv[i][1] == '/' || argv[i][1] == '?'); } else if (!vis_window_new(vis, argv[i])) { vis_die(vis, "Can not load `%s': %s\n", argv[i], strerror(errno)); } else if (cmd) { vis_prompt_cmd(vis, cmd); cmd = NULL; } } if (!vis->windows && vis->running) { if (!strcmp(argv[argc-1], "-")) { if (!vis_window_new(vis, NULL)) vis_die(vis, "Can not create empty buffer\n"); ssize_t len = 0; char buf[PIPE_BUF]; File *file = vis->win->file; Text *txt = file->text; file->is_stdin = true; while ((len = read(STDIN_FILENO, buf, sizeof buf)) > 0) text_insert(txt, text_size(txt), buf, len); if (len == -1) vis_die(vis, "Can not read from stdin\n"); text_snapshot(txt); int fd = open("/dev/tty", O_RDONLY); if (fd == -1) vis_die(vis, "Can not reopen stdin\n"); dup2(fd, STDIN_FILENO); close(fd); } else if (!vis_window_new(vis, NULL)) { vis_die(vis, "Can not create empty buffer\n"); } if (cmd) vis_prompt_cmd(vis, cmd); } }
static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) { Filerange sel = text_range_empty(); if (!win) return sam_execute(vis, NULL, cmd->cmd, NULL, &sel); bool ret = true; View *view = win->view; Text *txt = win->file->text; bool multiple_cursors = view_cursors_multiple(view); Cursor *primary = view_cursors_primary_get(view); for (Cursor *c = view_cursors(view), *next; c && ret; c = next) { next = view_cursors_next(c); size_t pos = view_cursors_pos(c); if (vis->mode->visual) { sel = view_cursors_selection_get(c); } else if (cmd->cmd->address) { /* convert a single line range to a goto line motion */ if (!multiple_cursors && cmd->cmd->cmddef->func == cmd_print) { Address *addr = cmd->cmd->address; switch (addr->type) { case '+': case '-': addr = addr->right; /* fall through */ case 'l': if (addr && addr->type == 'l' && !addr->right) addr->type = 'g'; break; } } sel = text_range_new(pos, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_POS) { sel = text_range_new(pos, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_LINE) { sel = text_object_line(txt, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_AFTER) { size_t next_line = text_line_next(txt, pos); sel = text_range_new(next_line, next_line); } else if (multiple_cursors) { sel = text_object_line(txt, pos); } else { sel = text_range_new(0, text_size(txt)); } if (text_range_valid(&sel)) ret &= sam_execute(vis, win, cmd->cmd, c, &sel); if (cmd->cmd->cmddef->flags & CMD_ONCE) break; } if (vis->win && vis->win->view == view && primary != view_cursors_primary_get(view)) view_cursors_primary_set(view_cursors(view)); return ret; }
void vis_prompt_show(Vis *vis, const char *title) { Win *active = vis->win; Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file, UI_OPTION_ONELINE); if (!prompt) return; if (vis->mode->visual) window_selection_save(active); Text *txt = prompt->file->text; text_insert(txt, text_size(txt), title, strlen(title)); Cursor *cursor = view_cursors_primary_get(prompt->view); view_cursors_scroll_to(cursor, text_size(txt)); prompt->parent = active; prompt->parent_mode = vis->mode; vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Backspace>", &prompt_backspace_binding); vis_mode_switch(vis, VIS_MODE_INSERT); }
//********************************************************************************** // //********************************************************************************** void CMessageBox::SetText( const CString & text ) { m_pText->SetText( text ); V2 text_size( m_pText->GetSize() + ( 2.f * BOX_BORDER ) ); if ( text_size.x < CFont::GetDefaultFont()->GetStringSize( m_szTitle ).x + ( 2.f * BOX_BORDER.x ) ) { text_size.x = CFont::GetDefaultFont()->GetStringSize( m_szTitle ).x + ( 2.f * BOX_BORDER.x ); } SetPos( V2( 0.5f * ( CGfx::s_ScreenWidth - text_size.x ), 0.5f * ( CGfx::s_ScreenHeight - text_size.y ) ) ); SetSize( text_size ); }
size_t text_search_backward(Text *txt, size_t pos, Regex *regex) { size_t start = 0; size_t end = pos; RegexMatch match[1]; bool found = !text_search_range_backward(txt, start, end, regex, 1, match, 0); if (!found) { start = pos + 1; end = text_size(txt); found = start < end && !text_search_range_backward(txt, start, end - start, regex, 1, match, 0); } return found ? match[0].start : pos; }
static void prompt_hide(Win *win) { Text *txt = win->file->text; size_t size = text_size(txt); /* make sure that file is new line terminated */ char lastchar; if (size > 1 && text_byte_get(txt, size-1, &lastchar) && lastchar != '\n') text_insert(txt, size, "\n", 1); /* remove empty entries */ Filerange line = text_object_line(txt, size); size_t line_size = text_range_size(&line); if (line_size <= 2) text_delete(txt, line.start, line_size); vis_window_close(win); }
void vis_message_show(Vis *vis, const char *msg) { if (!msg) return; if (!vis->message_window) vis->message_window = window_new_file(vis, vis->error_file, UI_OPTION_STATUSBAR); Win *win = vis->message_window; if (!win) return; Text *txt = win->file->text; size_t pos = text_size(txt); text_appendf(txt, "%s\n", msg); text_save(txt, NULL); view_cursor_to(win->view, pos); vis_window_focus(win); }
static const char *prompt_backspace(Vis *vis, const char *keys, const Arg *arg) { Win *prompt = vis->win; Text *txt = prompt->file->text; size_t size = text_size(txt); size_t pos = view_cursor_get(prompt->view); char c; if (pos == size && (pos == 1 || (size >= 2 && text_byte_get(txt, size-2, &c) && c == '\n'))) { prompt_restore(prompt); prompt_hide(prompt); } else { vis_operator(vis, VIS_OP_DELETE); vis_motion(vis, VIS_MOVE_CHAR_PREV); } return keys; }
void main() // Main function { badge_setup(); // Call badge setup while(1) // Main loop { clear(); text_size(LARGE); oledprint(" IR Rcv "); while(1) { irlen = receive(irbuf); // Check incoming IR if(irlen > 0) // Yes? exit while loop { break; } } clear(); // Display incoming message text_size(SMALL); oledprint(irbuf); cursor(0, 6); // Press button to repeat oledprint("Again? Any btn."); while(!buttons()); } }
void main() // Main function { badge_setup(); // Call badge setup text_size(SMALL); oledprint("Use SimpleIDE\nTerminal."); if(!stored(wilma)) // Check first, if repeat skip store(wilma); if(!stored(betty)) store(betty); if(!stored(fred)) // ...but if not repeat, store store(fred); if(!stored(barney)) store(barney); contacts_displayAll(); // Display contacts }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { /* make a test window */ tw = text_new(); if (!hPrevInstance) { HICON hicon = LoadIcon(NULL, IDI_APPLICATION); text_register_class(hicon); } text_font(tw, "Courier New", 10); text_size(tw, 80, 80); text_drag(tw, "(", ") run\r"); /* show the text window */ if (!text_create(tw, "Application Name", nCmdShow)) { /* do the real work here */ /* TESTING */ int ch; int len; char *line = new char[256]; while ( (len = text_read_line(tw, line, 256-1)) != 0 ) { text_write_buf(tw, line, len); } /* while ( text_gets(tw, line, 256-1) ) { text_puts(tw, line); } */ /* while ( (ch = text_getch(tw, )) != 4 ) text_putch(tw, ch); */ } else { } /* clean up */ text_destroy(tw); /* end program */ return 0; }
static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) { Win *prompt = vis->win; View *view = prompt->view; Text *txt = prompt->file->text; Win *win = prompt->parent; char *cmd = NULL; Filerange range = view_selection_get(view); if (!text_range_valid(&range)) range = text_object_line(txt, view_cursor_get(view)); if (text_range_valid(&range)) cmd = text_bytes_alloc0(txt, range.start, text_range_size(&range)); if (!win || !cmd) { vis_info_show(vis, "Prompt window invalid\n"); prompt_restore(prompt); prompt_hide(prompt); free(cmd); return keys; } size_t len = strlen(cmd); if (len > 0 && cmd[len-1] == '\n') cmd[len-1] = '\0'; bool lastline = (range.end == text_size(txt)); prompt_restore(prompt); if (vis_prompt_cmd(vis, cmd)) { prompt_hide(prompt); if (!lastline) { text_delete(txt, range.start, text_range_size(&range)); text_appendf(txt, "%s\n", cmd); } } else { vis->win = prompt; vis->mode = &vis_modes[VIS_MODE_INSERT]; } free(cmd); vis_draw(vis); return keys; }
void main() // Main function { badge_setup(); // Start badge systems dt_run(dt); // Start system timer with dt oledprint("Day/Time"); // Display heading text_size(SMALL); // Change to small text while(1) // Main loop { dt = dt_get(); // Get system time int hrs = dt.h % 12; // Adjust to 12 hours if(dt.h == 0 || dt.h == 12) hrs = 12; cursor(0, 5); // Position cursor row 5 // Display time with formatting flags oledprint(" %04d.%02d.%02d\n\n %02d:%02d:%02d ", dt.y, dt.mo, dt.d, hrs, dt.m, dt.s); if(dt.h >= 12) oledprint("PM"); // Display AM/PM else oledprint("AM"); } }
void main() // Main function { badge_setup(); // Call badge setup oledprint("IR Send"); text_size(SMALL); cursor(0, 4); oledprint("P17 = Education\n"); oledprint("P16 = Sales\n"); oledprint("P15 = Support\n"); while(1) { int states = buttons(); if(states & 0b0111000) { rgbs(RED, RED); } switch(states) { case 0b0100000: irprint("%16s\n%32s\n", education.name, education.email); break; case 0b0010000: irprint("%16s\n%32s\n", sales.name, sales.email); break; case 0b0001000: irprint("%16s\n%32s\n", support.name, support.email); break; } if(states) { rgbs(OFF, OFF); pause(600); } } }
void action_do(Vis *vis, Action *a) { Win *win = vis->win; Text *txt = win->file->text; View *view = win->view; if (a->op == &vis_operators[VIS_OP_FILTER] && !vis->mode->visual) vis_mode_switch(vis, VIS_MODE_VISUAL_LINE); int count = MAX(a->count, 1); bool repeatable = a->op && !vis->macro_operator; bool multiple_cursors = view_cursors_multiple(view); bool linewise = !(a->type & CHARWISE) && ( a->type & LINEWISE || (a->movement && a->movement->type & LINEWISE) || vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE]); for (Cursor *cursor = view_cursors(view), *next; cursor; cursor = next) { next = view_cursors_next(cursor); size_t pos = view_cursors_pos(cursor); Register *reg = multiple_cursors ? view_cursors_register(cursor) : a->reg; if (!reg) reg = &vis->registers[win->file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT]; OperatorContext c = { .count = count, .pos = pos, .newpos = EPOS, .range = text_range_empty(), .reg = reg, .linewise = linewise, .arg = &a->arg, }; if (a->movement) { size_t start = pos; for (int i = 0; i < count; i++) { size_t pos_prev = pos; if (a->movement->txt) pos = a->movement->txt(txt, pos); else if (a->movement->cur) pos = a->movement->cur(cursor); else if (a->movement->file) pos = a->movement->file(vis, vis->win->file, pos); else if (a->movement->vis) pos = a->movement->vis(vis, txt, pos); else if (a->movement->view) pos = a->movement->view(vis, view); else if (a->movement->win) pos = a->movement->win(vis, win, pos); else if (a->movement->user) pos = a->movement->user(vis, win, a->movement->data, pos); if (pos == EPOS || a->movement->type & IDEMPOTENT || pos == pos_prev) break; } if (pos == EPOS) { c.range.start = start; c.range.end = start; pos = start; } else { c.range = text_range_new(start, pos); c.newpos = pos; } if (!a->op) { if (a->movement->type & CHARWISE) view_cursors_scroll_to(cursor, pos); else view_cursors_to(cursor, pos); if (vis->mode->visual) c.range = view_cursors_selection_get(cursor); if (a->movement->type & JUMP) window_jumplist_add(win, pos); else window_jumplist_invalidate(win); } else if (a->movement->type & INCLUSIVE || (linewise && a->movement->type & LINEWISE_INCLUSIVE)) { c.range.end = text_char_next(txt, c.range.end); } } else if (a->textobj) { if (vis->mode->visual) c.range = view_cursors_selection_get(cursor); else c.range.start = c.range.end = pos; for (int i = 0; i < count; i++) { Filerange r = text_range_empty(); if (a->textobj->txt) r = a->textobj->txt(txt, pos); else if (a->textobj->vis) r = a->textobj->vis(vis, txt, pos); else if (a->textobj->user) r = a->textobj->user(vis, win, a->textobj->data, pos); if (!text_range_valid(&r)) break; if (a->textobj->type & OUTER) { r.start--; r.end++; } if (a->textobj->type & SPLIT) c.range = r; else c.range = text_range_union(&c.range, &r); if (i < count - 1) pos = c.range.end + 1; } } else if (vis->mode->visual) { c.range = view_cursors_selection_get(cursor); if (!text_range_valid(&c.range)) c.range.start = c.range.end = pos; } if (linewise && vis->mode != &vis_modes[VIS_MODE_VISUAL]) c.range = text_range_linewise(txt, &c.range); if (vis->mode->visual) { view_cursors_selection_set(cursor, &c.range); if (vis->mode == &vis_modes[VIS_MODE_VISUAL] || a->textobj) view_cursors_selection_sync(cursor); } if (a->op) { size_t pos = a->op->func(vis, txt, &c); if (pos == EPOS) { view_cursors_dispose(cursor); } else if (pos <= text_size(txt)) { /* moving the cursor will affect the selection. * because we want to be able to later restore * the old selection we update it again before * leaving visual mode. */ Filerange sel = view_cursors_selection_get(cursor); view_cursors_to(cursor, pos); if (vis->mode->visual) { if (sel.start == EPOS && sel.end == EPOS) sel = c.range; else if (sel.start == EPOS) sel = text_range_new(c.range.start, sel.end); else if (sel.end == EPOS) sel = text_range_new(c.range.start, sel.start); if (vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE]) sel = text_range_linewise(txt, &sel); view_cursors_selection_set(cursor, &sel); } } } } if (a->op) { /* we do not support visual repeat, still do something resonable */ if (vis->mode->visual && !a->movement && !a->textobj) a->movement = &vis_motions[VIS_MOVE_NOP]; /* operator implementations must not change the mode, * they might get called multiple times (once for every cursor) */ if (a->op == &vis_operators[VIS_OP_INSERT] || a->op == &vis_operators[VIS_OP_CHANGE]) { vis_mode_switch(vis, VIS_MODE_INSERT); } else if (a->op == &vis_operators[VIS_OP_REPLACE]) { vis_mode_switch(vis, VIS_MODE_REPLACE); } else if (a->op == &vis_operators[VIS_OP_FILTER]) { if (a->arg.s) vis_cmd(vis, a->arg.s); else vis_prompt_show(vis, ":|"); } else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR_PENDING]) { mode_set(vis, vis->mode_prev); } else if (vis->mode->visual) { vis_mode_switch(vis, VIS_MODE_NORMAL); } text_snapshot(txt); vis_draw(vis); } if (a != &vis->action_prev) { if (repeatable) { if (!a->macro) a->macro = vis->macro_operator; vis->action_prev = *a; } action_reset(a); } } void action_reset(Action *a) { memset(a, 0, sizeof(*a)); a->count = VIS_COUNT_UNKNOWN; }
void main() // Main function { badge_setup(); // Call badge setup oledprint("Any BTN\nfor Menu"); pause(1200); while(1) { clear(); // Display screen name text_size(LARGE); oledprint("%s", screenName); while(!buttons()); // Wait for button press text_size(SMALL); // Menu clear(); oledprint(" MENU "); oledprint("P17-Send "); oledprint(" Receive-P27\n"); oledprint("P15-Upload "); oledprint(" Back-P25\n"); oledprint(" Erase-OSH-All "); pause(250); while((states = buttons()) == 0); // Wait for button press clear(); // Get ready to display operation text_size(LARGE); switch(states) // Handle button press { case 0b0100000: // P17 pressed, send IR clear; oledprint("Sending"); rgbs(RED, RED); send(my); rgbs(OFF, OFF); pause(50); continue; // Back to while(1) case 0b0000001: // P27 pressed break; // Skip to IR receive code case 0b0001000: clear(); oledprint("Upload ..."); contacts_displayAll(); oledprint("Done"); pause(250); continue; // Back to while(1) case 0b1000000: // OSH pressed, erase EEPROM clear(); oledprint("CONFIRM"); pause(500); text_size(SMALL); cursor(0, 4); oledprint("Yes-OSH\n\n"); oledprint("No-Any other btn"); while(!(states = buttons())); // Get confirmation if(states == 0b1000000) // Yes, erase { text_size(LARGE); clear(); oledprint("Wait 20s..."); contacts_eraseAll(); oledprint("Done!"); pause(250); } else // No, don't erase { clear(); pause(250); } continue; // Back to while(1) default: continue; // Back to while(1) } // P27 has to have been pressed to get to here clear(); oledprint("IR Rcv"); // Display ready for IR cursor(0, 7); text_size(SMALL); oledprint(" Back-P25"); // Wait for IR message pause(250); irclear(); // Clear the IR buffers while(1) { irlenb = receive(irbuf); if(irlenb > 0) break; states = buttons(); if(states == 0b0000100) { led(0, OFF); break; } led(0, ON); pause(150); led(0, OFF); pause(150); } if(states == 0b0000100) continue; clear(); // Menu, what to do with data oledprint(irbuf); cursor(0, 5); oledprint(" Store-P26"); cursor(0, 6); oledprint(" Discard-P25"); while((states = buttons()) == 0); // Wait for button press text_size(LARGE); clear(); if(states == 0b0000010) // If P26, store to EEPROM { if(!stored(irbuf)) store(irbuf); oledprint("Stored"); } if(states == 0b0000100) // if(P25), discard { oledprint("Discard"); } pause(500); } }
int TextTest(int verbose, struct cfg *cfg, char *args[]) { tchar buf[1024]; tchar *hello = TEXT("hello"); tchar *a = TEXT("a"); tchar *e = TEXT(""); tchar *cpy; cfg = NULL; *args = NULL; verbose = 1; /* text_length */ T(text_length(NULL, NULL) == 0); T(text_length(hello, NULL) == 0); T(text_length(hello + 3, hello) == 0); T(text_length(hello, hello) == 0); T(text_length(hello, hello + 1) == 0); T(text_length(hello, hello + 4) == 0); T(text_length(a, a + 1) == 0); T(text_length(a, a + 2) == 1); T(text_length(a + 1, a + 2) == 0); T(text_length(hello, hello + 100) == 5); /* text_size */ T(text_size(NULL, NULL) == 0); T(text_size(hello, NULL) == 0); T(text_size(hello + 3, hello) == 0); T(text_size(hello, hello) == 0); T(text_size(hello, hello + 1) == 0); T(text_size(hello, hello + 4) == 0); T(text_size(a, a + 1) == 0); T(text_size(a, a + 2) == (2 * sizeof *a)); T(text_size(a + 1, a + 2) == (1 * sizeof *a)); T(text_size(hello, hello + 100) == (6 * sizeof *hello)); /* text_copy */ T(text_copy(hello, hello + 100, NULL, buf + 1024, 0) == 0); T(text_copy(hello, hello + 100, buf + 3, buf, 0) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(NULL, hello + 100, buf, buf + 1024, 0) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello + 3, hello, buf, buf + 1024, 0) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 100, 1) == 1); T(tcsncmp(TEXT("h"), buf, 100) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 100, 5) == 5); T(tcsncmp(hello, buf, 100) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 1024, 0) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(e, e + 100, buf, buf + 1024, 100) == 0); T(tcsncmp(e, buf, 100) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 1024, 100) == 5); T(tcsncmp(hello, buf, 100) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 1, buf, buf + 1024, 100) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 5, buf, buf + 1024, 100) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 6, buf, buf + 1024, 100) == 5); T(tcsncmp(hello, buf, 100) == 0); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 1, 100) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 5, 100) == 0); T(buf[0] == TEXT('\0')); memset(buf, 'x', 1024 * sizeof(tchar)); T(text_copy(hello, hello + 100, buf, buf + 6, 100) == 5); T(tcsncmp(hello, buf, 100) == 0); /* text_copy_new */ T(text_copy_new(hello, hello + 100, &cpy, 100, NULL) == 5); T(tcsncmp(hello, cpy, 100) == 0); allocator_free(NULL, cpy); T(text_copy_new(hello, hello + 100, NULL, 100, NULL) == 0); T(text_copy_new(NULL, hello + 100, &cpy, 100, NULL) == 0); T(cpy == NULL); T(text_copy_new(hello + 3, hello, &cpy, 100, NULL) == 0); T(cpy == NULL); T(text_copy_new(hello, hello + 100, &cpy, 0, NULL) == 0); T(tcsncmp(e, cpy, 100) == 0); allocator_free(NULL, cpy); T(text_copy_new(hello, hello + 100, &cpy, 4, NULL) == 4); T(tcsncmp(TEXT("hell"), cpy, 100) == 0); allocator_free(NULL, cpy); T(text_copy_new(hello, hello + 100, &cpy, 5, NULL) == 5); T(tcsncmp(hello, cpy, 100) == 0); allocator_free(NULL, cpy); return 0; }