aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/view.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-09 16:54:26 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-09 18:22:21 +0200
commit4f231871a0208ec9bcc2679fce25d3b9795d1597 (patch)
treebdc9055166fe236f009c6640acf53b6706310c27 /src/view.c
parent41ab5cf0289dab60ac1ddc97cf9680ee2468ea6c (diff)
downloadsciteco-4f231871a0208ec9bcc2679fce25d3b9795d1597.tar.gz
added raw ANSI mode to facilitate 8-bit clean editing (refs #5)
* When enabled with bit 2 in the ED flags (0,4ED), all registers and buffers will get the raw ANSI encoding (as if 0EE had been called on them). You can still manually change the encoding, eg. by calling 65001EE afterwards. * Also the ANSI mode sets up character representations for all bytes >= 0x80. This is currently done only depending on the ED flag, not when setting 0EE. * Since setting 16,4ED for 8-bit clean editing in a macro can be tricky - the default unnamed buffer will still be at UTF-8 and at least a bunch of environment registers as well - we added the command line option `--8bit` (short `-8`) which configures the ED flags very early on. As another advantage you can mung the profile in 8-bit mode as well when using SciTECO as a sort of interactive hex editor. * Disable UTF-8 checks in 8-bit clean mode (sample.teco_ini).
Diffstat (limited to 'src/view.c')
-rw-r--r--src/view.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/view.c b/src/view.c
index 291c06b..0d1d168 100644
--- a/src/view.c
+++ b/src/view.c
@@ -72,6 +72,27 @@ teco_view_setup(teco_view_t *ctx)
*/
teco_view_ssm(ctx, SCI_SETMARGINWIDTHN, 1, 0);
+ if (teco_ed & TECO_ED_DEFAULT_ANSI) {
+ /*
+ * Configure a single-byte codepage/charset.
+ * This requires setting it on all of the possible styles.
+ * Fortunately, we can do it before SCI_STYLECLEARALL.
+ * This is important only for display purposes - other than that
+ * all single-byte encodings are handled the same.
+ */
+ teco_view_ssm(ctx, SCI_STYLESETCHARACTERSET, STYLE_DEFAULT, SC_CHARSET_ANSI);
+ /* 0 is used for ALL single-byte encodings */
+ teco_view_ssm(ctx, SCI_SETCODEPAGE, 0, 0);
+ } else {
+ /*
+ * Documents are UTF-8 by default and all UTF-8 documents
+ * are expected to have a character index.
+ * This is a property of the document, instead of the view.
+ */
+ teco_view_ssm(ctx, SCI_ALLOCATELINECHARACTERINDEX,
+ SC_LINECHARACTERINDEX_UTF32, 0);
+ }
+
/*
* Set some basic styles in order to provide
* a consistent look across UIs if no profile
@@ -118,14 +139,6 @@ teco_view_setup(teco_view_t *ctx)
* the representations only once.
*/
teco_view_set_representations(ctx);
-
- /*
- * Documents are UTF-8 by default and all UTF-8 documents
- * are expected to have a character index.
- * This is a property of the document, instead of the view.
- */
- teco_view_ssm(ctx, SCI_ALLOCATELINECHARACTERINDEX,
- SC_LINECHARACTERINDEX_UTF32, 0);
}
TECO_DEFINE_UNDO_CALL(teco_view_ssm, teco_view_t *, unsigned int, uptr_t, sptr_t);
@@ -145,6 +158,28 @@ teco_view_set_representations(teco_view_t *ctx)
gchar buf[] = {(gchar)cc, '\0'};
teco_view_ssm(ctx, SCI_SETREPRESENTATION, (uptr_t)buf, (sptr_t)reps[cc]);
}
+
+ if (teco_ed & TECO_ED_DEFAULT_ANSI) {
+ /*
+ * Non-ANSI chars should be visible somehow.
+ * This would best be done always when changing the
+ * encoding to 0, but it would be kind of expensive.
+ *
+ * FIXME: On the other hand, this could cause problems
+ * when setting SC_CP_UTF8 later on.
+ */
+ for (guint cc = 0x80; cc <= 0xFF; cc++) {
+ gchar buf[] = {(gchar)cc, '\0'};
+ gchar rep[2+1];
+ /*
+ * Hexadecimal is poorly supported in SciTECO, but
+ * multiple decimal numbers one after another look
+ * confusing, esp. in Curses.
+ */
+ g_snprintf(rep, sizeof(rep), "%02X", cc);
+ teco_view_ssm(ctx, SCI_SETREPRESENTATION, (uptr_t)buf, (sptr_t)rep);
+ }
+ }
}
/**