From c1be4e985b7fac1823fc49836fb45b7011aa4d67 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Debian Linux)" <rob@synchro.net>
Date: Sat, 1 Apr 2023 09:46:50 -0700
Subject: [PATCH] Add method: query_ctda() - Query CTerm Device Attributes

Returns an array of attributes (digits), if valid response

Now Nightfox, you can query SyncTERM (only) to see if it supports Pixel ops
(e.g. Sixel) is supported at the moment, using:

  cterm_lib.query_ctda(cterm_lib.cterm_device_attributes.pixelops_supported)

- will return true if pixel operations are supported

Other dynamic terminal capabilities (e.g. depdendant on the output mode that
SyncTERM is run in) can be detected with this method. But note: the values
returned in SyncTERM's CTDA query-response do not exaclty match the values
documented in cterm.txt. So use the constants from cterm_lib.js instead.
---
 exec/load/cterm_lib.js | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/exec/load/cterm_lib.js b/exec/load/cterm_lib.js
index 08413a9d6a..80064b01b5 100644
--- a/exec/load/cterm_lib.js
+++ b/exec/load/cterm_lib.js
@@ -21,6 +21,16 @@ const font_state_field_result = 1;
 const font_state_field_style = 2;
 const da_ver_major = 0;
 const da_ver_minor = 1;
+const cterm_device_attributes = {
+	valid:'0',
+	loadable_fonts:'1',
+	bright_background:'2',
+	palette_settable:'3',
+	pixelops_supported:'4',
+	font_selectable:'5',
+	extended_palette:'6',
+	mouse_available:'7'
+};
 
 if(console.cterm_version === undefined || console.cterm_version < 0) {
 	var response = query_da();
@@ -192,6 +202,17 @@ function query_fontdim()
 	return false;
 }
 
+function query_ctda(which)
+{
+	var response = query("\x1b[<c");
+	if(response.substr(0, 3) != "\x1b[<" || response.substr(-1) != "c")
+		return false;
+	var attributes = response.slice(3, -1).split(/;/);
+	if(which !== undefined)
+		return attributes.indexOf(which) >= 0;
+	return attributes;
+}
+
 function fontsize(n)
 {
 	switch(n) {
-- 
GitLab