poe

Уређивач .po фајлова
git clone https://git.sr.ht/~strahinja/poe
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

draw.h (4681B)


      1 /* This program is licensed under the terms of GNU GPL v3 or (at your option)
      2  * any later version. Copyright (C) 2021-2024  Страхиња Радић.
      3  * See the file LICENSE for exact copyright and license details. */
      4 
      5 #include <stddef.h>
      6 #include <termios.h>
      7 #include <unistd.h>
      8 #include <wchar.h>
      9 
     10 #define TB_OPT_V1_COMPAT
     11 #include "termbox.h"
     12 
     13 #define BORDER_NW  ((uint32_t)0x250c)
     14 #define BORDER_NE  ((uint32_t)0x2510)
     15 #define BORDER_SW  ((uint32_t)0x2514)
     16 #define BORDER_SE  ((uint32_t)0x2518)
     17 #define BORDER_VER ((uint32_t)0x2502)
     18 #define BORDER_HOR ((uint32_t)0x2500)
     19 
     20 #define EDIT_WIDTH    70
     21 #define EDIT_HEIGHT   20
     22 #define HELP_WIDTH    50
     23 #define HELP_HEIGHT   22
     24 #define SEARCH_WIDTH  20
     25 #define SEARCH_HEIGHT 4
     26 #define TAB_SIZE      8
     27 #define MAXSEARCH     (512 + 1)
     28 
     29 typedef enum { LEFT, CENTER, RIGHT } Alignment;
     30 
     31 typedef enum { UNCHANGED, SET, CLEARED } FlagChange;
     32 
     33 struct BufferLine {
     34 	uint32_t* text;
     35 	size_t length;
     36 	uint16_t fg;
     37 	uint16_t bg;
     38 };
     39 
     40 struct DrawState {
     41 	char* error;
     42 	char* prompt;
     43 	char* filename;
     44 	char* real_filename; /* what symlink points to */
     45 	char* backup_filename;
     46 	size_t rfn_len;
     47 	uint32_t* search;
     48 	struct BufferLine* input_buffer; /* edit box */
     49 	int input_column;
     50 	int input_row;
     51 	int input_first_shown_column;
     52 	int input_first_shown_row;
     53 	int input_rows_count;
     54 	int input_display_column;
     55 	FlagChange input_changed_fuzzy;
     56 	int saved_column;
     57 	struct BufferLine* info_buffer; /* information pane above
     58 					 * edit box */
     59 	int info_first_shown_column;
     60 	int info_first_shown_row;
     61 	int info_rows_count;
     62 	int info_rows_maxlen;
     63 	int help_width;
     64 	int edit_width;
     65 	int search_width;
     66 	struct BufferLine* paste_buffer;
     67 	int paste_rows_count;
     68 	int search_column;
     69 	int search_first_shown_column;
     70 	int search_display_column;
     71 	struct PoEntry* entries;
     72 	long nplurals;
     73 	void (*prompt_callback)(struct DrawState*, struct tb_event*);
     74 	int running;
     75 	int dirty;
     76 	int dirty_before_edit;
     77 	size_t fuzzy_before_edit;
     78 	int in_prompt;
     79 	int show_help;
     80 	int show_edit;
     81 	int edit_info_focused;
     82 	int show_search;
     83 	int maxx;
     84 	int maxy;
     85 	size_t msgid_number; /* "real" msgid (inc. obsolete msgids) */
     86 	size_t msgid_count;  /* without obsolete msgids */
     87 	size_t msgid_size;
     88 	size_t fuzzy_count;
     89 	size_t untranslated_count;
     90 	size_t obsolete_count;
     91 	size_t obsolete_at_end_count;
     92 	size_t real_msgid_count; /* msgid_count + obsolete_count */
     93 	int msgstr_index;	 /* with msgstr[] */
     94 	size_t first_shown_msgid;
     95 	int backup_possible; /* is saving backup possible? */
     96 };
     97 
     98 struct Key {
     99 	struct tb_event ev;
    100 	int (*callback)(struct DrawState*);
    101 };
    102 
    103 struct StatusSegment {
    104 	const char* format;
    105 	void (*callback)(char*, size_t, const char*, const struct DrawState*);
    106 	uint16_t fg;
    107 	uint16_t bg;
    108 	Alignment alignment;
    109 };
    110 
    111 void init_bufferline(struct BufferLine* bl);
    112 void free_bufferline(struct BufferLine* bl);
    113 void init_drawstate(struct DrawState* state, char* error, char* filename,
    114 	char* prompt);
    115 void free_drawstate(struct DrawState* state);
    116 struct DrawState* set_nplurals(struct DrawState* state, struct PoEntry* entry);
    117 size_t display_length(const struct DrawState* state, uint32_t* buffer,
    118 	const size_t max_index);
    119 size_t input_length(const struct DrawState* state, uint32_t* buffer,
    120 	const size_t max_index);
    121 int calculate_help_width(const struct DrawState* state);
    122 int calculate_edit_width(const struct DrawState* state);
    123 int calculate_search_width(const struct DrawState* state);
    124 void draw_rect(const int startx, const int endx, const int starty,
    125 	const int endy, const uint16_t fg, const uint16_t bg);
    126 void draw_box(const int startx, const int endx, const int starty,
    127 	const int endy, const uint16_t fg, const uint16_t bg);
    128 const char* draw_string(const int x, const int y, const uint16_t fg,
    129 	const uint16_t bg, const char* s, const int max_cols,
    130 	const int fill_cols, const int padding_left, const int padding_right,
    131 	const Alignment align, const int ds, const int fill,
    132 	const uint32_t* srch, const uint16_t sfg, const uint16_t sbg);
    133 void u32_draw_string(const int x, const int y, const uint16_t fg,
    134 	const uint16_t bg, const uint32_t* s, const int max_cols,
    135 	const int fill_cols, const int padding_left, const int padding_right,
    136 	const Alignment align, const int ds, const int fill,
    137 	const uint32_t* srch, const uint16_t sfg, const uint16_t sbg);
    138 const struct DrawState* draw_help(const struct DrawState* state);
    139 const struct DrawState* draw_editbox(const struct DrawState* state);
    140 const struct DrawState* draw_search(const struct DrawState* state);
    141 const struct DrawState* draw_status(const struct DrawState* state);
    142 const struct DrawState* draw_list_visible(const struct DrawState* state);
    143 const struct DrawState* draw(const struct DrawState* state);