+static struct output_driver *
+ascii_create (struct file_handle *fh, enum settings_output_devices device_type,
+ struct string_map *o)
+{
+ enum { BOX_ASCII, BOX_UNICODE } box;
+ struct output_driver *d;
+ struct ascii_driver *a;
+
+ a = xzalloc (sizeof *a);
+ d = &a->driver;
+ output_driver_init (&a->driver, &ascii_driver_class, fh_get_file_name (fh), device_type);
+ a->append = parse_boolean (opt (d, o, "append", "false"));
+ a->emphasis = parse_boolean (opt (d, o, "emphasis", "false"));
+
+ a->chart_file_name = parse_chart_file_name (opt (d, o, "charts", fh_get_file_name (fh)));
+ a->handle = fh;
+
+
+ bool terminal = !strcmp (fh_get_file_name (fh), "-") && isatty (1);
+ a->width = parse_page_size (opt (d, o, "width", "-1"));
+ a->width_mode = (a->width > 0 ? FIXED_WIDTH
+ : terminal ? TERMINAL_WIDTH
+ : VIEW_WIDTH);
+ a->min_hbreak = parse_int (opt (d, o, "min-hbreak", "-1"), -1, INT_MAX);
+
+#ifdef HAVE_CAIRO
+ a->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
+ a->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
+#endif
+
+ const char *default_box = (terminal && (!strcmp (locale_charset (), "UTF-8")
+ || term_is_utf8_xterm ())
+ ? "unicode" : "ascii");
+ box = parse_enum (opt (d, o, "box", default_box),
+ "ascii", BOX_ASCII,
+ "unicode", BOX_UNICODE,
+ NULL_SENTINEL);
+ a->box = box == BOX_ASCII ? ascii_box_chars : unicode_box_chars;
+
+ a->file = NULL;
+ a->error = false;
+ a->lines = NULL;
+ a->allocated_lines = 0;
+ a->chart_cnt = 0;
+ a->object_cnt = 0;
+
+ static const struct render_ops ascii_render_ops = {
+ .draw_line = ascii_draw_line,
+ .measure_cell_width = ascii_measure_cell_width,
+ .measure_cell_height = ascii_measure_cell_height,
+ .adjust_break = NULL,
+ .draw_cell = ascii_draw_cell,
+ };
+ a->params.ops = &ascii_render_ops;
+ a->params.aux = a;
+ a->params.size[H] = a->width;
+ a->params.size[V] = INT_MAX;
+ a->params.font_size[H] = 1;
+ a->params.font_size[V] = 1;
+
+ static const int ascii_line_widths[RENDER_N_LINES] = {
+ [RENDER_LINE_NONE] = 0,
+ [RENDER_LINE_SINGLE] = 1,
+ [RENDER_LINE_DASHED] = 1,
+ [RENDER_LINE_THICK] = 1,
+ [RENDER_LINE_THIN] = 1,
+ [RENDER_LINE_DOUBLE] = 1,
+ };
+ a->params.line_widths = ascii_line_widths;
+ a->params.supports_margins = false;
+ a->params.rtl = render_direction_rtl ();