Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit a844754

Browse files
committed
WIP
1 parent 26dbcd6 commit a844754

File tree

5 files changed

+108
-19
lines changed

5 files changed

+108
-19
lines changed

src/components/codePanoItem.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ export class CodePanoItem extends PanoItem {
4949
this.setTextStyle();
5050
});
5151

52-
this.codeItemSettings.connect('changed', (_source, key) => {
52+
this.codeItemSettings.connect('changed', (_source, _key) => {
53+
if (this._type !== 'code') {
54+
return;
55+
}
56+
57+
this.setCodeStyle(undefined);
58+
});
59+
60+
ext.markdownDetector?.connect('changed', (_source, key) => {
5361
if (key === 'code-highlighter-enabled') {
5462
const isEnabled = this.codeItemSettings.get_boolean('code-highlighter-enabled');
5563

@@ -143,7 +151,9 @@ export class CodePanoItem extends PanoItem {
143151
this.label.set_style(`font-size: ${bodyFontSize}px; font-family: ${bodyFontFamily};`);
144152

145153
if (markdown) {
154+
debug('SET markup: ' + markdown);
146155
this.label.clutterText.set_markup(markdown);
156+
//this.label.ensure_style();
147157
}
148158
}
149159

src/utils/code/pygments.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ export class PygmentsCodeHighlighter extends CodeHighlighter {
173173
let cancellable: CancellableWrapper | undefined;
174174

175175
try {
176-
const proc = this._launcher.spawnv([this.cliName, '-l', language, '-f', 'pango', ...this.getOptionsForCLI()]);
176+
const cliOptions = await this.getOptionsForCLI();
177+
console.log('cliOptions: ' + cliOptions.join(', '));
178+
179+
const proc = this._launcher.spawnv([this.cliName, '-l', language, '-f', 'pango', ...cliOptions]);
177180

178181
cancellable = this.cancellableCollection.add(new Gio.Cancellable());
179182

@@ -209,11 +212,39 @@ export class PygmentsCodeHighlighter extends CodeHighlighter {
209212
}
210213
}
211214

215+
private goodStyleValues = [
216+
'pano',
217+
'material',
218+
'solarized-dark',
219+
'github-dark',
220+
'github-dark-high-contrast',
221+
'fruity',
222+
'pitaya-smoothie',
223+
'greative',
224+
];
225+
226+
private getDefaultStyle(styles: string[]) {
227+
let defaultStyleValue: string | number = 0;
228+
229+
for (const goodStyleValue of this.goodStyleValues) {
230+
if (typeof defaultStyleValue !== 'number') {
231+
break;
232+
}
233+
234+
if (styles.includes(goodStyleValue)) {
235+
defaultStyleValue = goodStyleValue;
236+
}
237+
}
238+
239+
return defaultStyleValue;
240+
}
241+
212242
private getOptionsForCLI(): string[] {
213243
const options: string[] = [];
214244

215-
for (const [name, value] of Object.entries(this._options)) {
216-
options.push(`-P=${name}=${value}`);
245+
const style = this._options.style;
246+
if (style) {
247+
options.push(`-Pstyle=${style}`);
217248
}
218249

219250
return options;
@@ -241,17 +272,21 @@ export class PygmentsCodeHighlighter extends CodeHighlighter {
241272
return {};
242273
}
243274

275+
//TODO: add "title" widget between those recommended ones, and the other ones sorted
244276
const styles = Object.keys(this._features.styles);
245-
styles.sort();
277+
styles.sort((a, b) => {
278+
if (this.goodStyleValues.includes(a)) {
279+
return -1;
280+
}
246281

247-
let defaultStyleValue: string | number = 0;
248-
if (styles.includes('default')) {
249-
defaultStyleValue = 'default';
250-
}
282+
if (this.goodStyleValues.includes(b)) {
283+
return 1;
284+
}
251285

252-
if (styles.includes('pano')) {
253-
defaultStyleValue = 'pano';
254-
}
286+
return b.localeCompare(b);
287+
});
288+
289+
const defaultStyleValue: string | number = this.getDefaultStyle(styles);
255290

256291
return {
257292
style: {

src/utils/pango.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Gio from '@girs/gio-2.0';
22
import GLib from '@girs/glib-2.0';
33
import type { ExtensionBase } from '@girs/gnome-shell/dist/extensions/sharedInternals';
4+
import GObject from '@girs/gobject-2.0';
45
import { ActiveCollection } from '@pano/utils/code/active';
56
import type { CodeHighlighter, CodeHighlighterMetaData, Language } from '@pano/utils/code/highlight';
67
import { PygmentsCodeHighlighter } from '@pano/utils/code/pygments';
8+
import { registerGObjectClass, SignalRepresentationType, SignalsDefinition } from '@pano/utils/gjs';
79
import { logger } from '@pano/utils/shell';
810

911
//TODO: add highlight.js back, if it is installed and can be found via "require()"" or dynamic "await import()""
@@ -117,7 +119,24 @@ class TaskScheduler {
117119

118120
type LoadCallback = () => void | Promise<void>;
119121

120-
export class PangoMarkdown {
122+
export type PangoMarkdownSignalType = 'changed';
123+
124+
interface PangoMarkdownSignals extends SignalsDefinition<PangoMarkdownSignalType> {
125+
changed: SignalRepresentationType<[GObject.GType<string>]>;
126+
}
127+
128+
@registerGObjectClass
129+
export class PangoMarkdown extends GObject.Object {
130+
static metaInfo: GObject.MetaInfo<Record<string, never>, Record<string, never>, PangoMarkdownSignals> = {
131+
GTypeName: 'PangoMarkdown',
132+
Signals: {
133+
changed: {
134+
param_types: [GObject.TYPE_STRING],
135+
accumulator: 0,
136+
},
137+
},
138+
};
139+
121140
private _detectedHighlighter: CodeHighlighter[] = [];
122141
private _currentHighlighter: CodeHighlighter | null = null;
123142

@@ -136,6 +155,7 @@ export class PangoMarkdown {
136155
enableWatch = false,
137156
schedulerConcurrency: number = 4,
138157
) {
158+
super();
139159
this._scheduler = new TaskScheduler(schedulerConcurrency);
140160

141161
this._availableCodeHighlighter = [new PygmentsCodeHighlighter(ext)];
@@ -251,31 +271,39 @@ export class PangoMarkdown {
251271
public static readonly enabledKey = 'code-highlighter-enabled';
252272

253273
private enableWatch(settings: Gio.Settings) {
254-
const settingsChanged = async () => {
274+
const settingsChanged = async (key: string) => {
255275
const isEnabled = settings.get_boolean(PangoMarkdown.enabledKey);
256276
if (!isEnabled) {
257277
this._currentHighlighter = null;
278+
this.emit('changed', key);
258279
return;
259280
}
260281

261282
const highlighterValue = settings.get_uint(PangoMarkdown.codeHighlighterKey);
262283

263284
await this.detectHighlighter(PangoMarkdown.availableCodeHighlighter[highlighterValue]!.name);
285+
this.emit('changed', key);
264286
};
265287

266-
settings.connect(`changed::${PangoMarkdown.enabledKey}`, settingsChanged);
288+
settings.connect(`changed::${PangoMarkdown.enabledKey}`, () => settingsChanged(PangoMarkdown.enabledKey));
267289

268-
settings.connect(`changed::${PangoMarkdown.codeHighlighterKey}`, settingsChanged);
290+
settings.connect(`changed::${PangoMarkdown.codeHighlighterKey}`, () =>
291+
settingsChanged(PangoMarkdown.codeHighlighterKey),
292+
);
293+
294+
const charLengthKey = ' char-length';
295+
296+
settings.connect(`changed::${charLengthKey}`, () => settingsChanged(charLengthKey));
269297

270298
for (const codeHighlighter of this._availableCodeHighlighter) {
271-
const schemaKey = `changed::${PangoMarkdown.getSchemaKeyForOptions(codeHighlighter)}`;
299+
const optionSchemaKey = PangoMarkdown.getSchemaKeyForOptions(codeHighlighter);
300+
const schemaKey = `changed::${optionSchemaKey}`;
272301
settings.connect(schemaKey, () => {
273302
if (this._currentHighlighter?.name === codeHighlighter.name) {
274303
this._currentHighlighter.options = settings.get_string(schemaKey);
304+
this.emit('changed', optionSchemaKey);
275305
}
276306
});
277-
278-
codeHighlighter;
279307
}
280308
}
281309

src/utils/panoItemFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ const findOrCreateDbItem = async (ext: PanoExtension, clip: ClipboardContent): P
205205
.get_child('code-item')
206206
.get_double('highlighter-detection-relevance');
207207

208+
debug('GIOT language: ' + detectedLanguage?.language + 'with relevance ' + detectedLanguage?.relevance);
209+
208210
if (ext.markdownDetector && detectedLanguage && detectedLanguage.relevance >= minimumLanguageRelevance) {
209211
return db.save({
210212
content: value,

test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# yarn run build
4+
5+
export SHELL_DEBUG=all
6+
7+
#export G_MESSAGES_DEBUG=all
8+
9+
export MUTTER_DEBUG_DUMMY_MODE_SPECS=1366x768
10+
11+
dbus-run-session -- gnome-shell --nested --wayland > test.txt 2>&1
12+
13+
14+
# TODO: use formatn or gettextn and overhaul notifications for gnome 46

0 commit comments

Comments
 (0)