init illogical-impulse

This commit is contained in:
end-4
2023-12-25 18:17:47 +07:00
parent 16b0d77075
commit 9b2460c12b
55 changed files with 3575 additions and 902 deletions
+3 -3
View File
@@ -56,9 +56,9 @@ export default {
};
// We don't want context menus of the bar's tray go under the rounded corner below,
// So bar is returned after 1ms, making it get spawned after the corner
// And having an Utils.timeout in that window array just gives an error
// so bar is returned after default export, making it get spawned after the corner
// (having an Utils.timeout in that window array just gives an error)
// Not having it in default export is fine since we don't need to toggle it
Bar();
// uwu
// uwu
+1 -1
View File
@@ -29,7 +29,7 @@
<style name="current-line" background="#3E3D32"/>
<style name="current-line-number" background="#eeeeec"/>
<style name="draw-spaces" foreground="#babdb6"/>
<style name="background-pattern" background="#rgba(0,0,0,0)"/>
<style name="background-pattern" background="#000000"/>
<!-- Bracket Matching -->
<!-- <style name="bracket-match" foreground="white" background="grey"/> -->
+74 -12
View File
@@ -4,7 +4,7 @@ import { MaterialIcon } from './materialicon.js';
import { setupCursorHover } from './cursorhover.js';
const { Box, Button, Entry, EventBox, Icon, Label, Revealer, Scrollable, Stack } = Widget;
export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, ...props }) => {
export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, ...rest }) => {
let value = initValue;
const toggleIcon = Label({
className: `icon-material txt-bold ${value ? '' : 'txt-poof'}`,
@@ -37,25 +37,87 @@ export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, ...pr
]
});
const interactionWrapper = Button({
...props,
child: widgetContent,
setup: setupCursorHover,
onClicked: () => { // mouse up/kb press
value = !value;
toggleIcon.toggleClassName('switch-fg-toggling-false', false);
toggleIcon.label = `${value ? 'check' : ''}`;
toggleIcon.toggleClassName('txt-poof', !value);
if (!value) {
toggleIcon.label = '';
toggleIcon.toggleClassName('txt-poof', true);
}
toggleButtonIndicator.toggleClassName('switch-fg-true', value);
toggleButton.toggleClassName('switch-bg-true', value);
if(value) Utils.timeout(1, () => {
toggleIcon.label = 'check';
toggleIcon.toggleClassName('txt-poof', false);
})
onChange(interactionWrapper, value);
},
setup: (button) => {
button.connect('pressed', () => { // mouse down
toggleIcon.toggleClassName('txt-poof', true);
toggleIcon.toggleClassName('switch-fg-true', false);
if(!value) toggleIcon.toggleClassName('switch-fg-toggling-false', true);
});
}
setupCursorHover(button),
button.connect('pressed', () => { // mouse down
toggleIcon.toggleClassName('txt-poof', true);
toggleIcon.toggleClassName('switch-fg-true', false);
if (!value) toggleIcon.toggleClassName('switch-fg-toggling-false', true);
});
},
...rest,
});
return interactionWrapper;
}
}
export const ConfigSegmentedSelection = ({
icon, name, desc = '',
options = [{ name: 'Option 1', value: 0 }, { name: 'Option 2', value: 1 }],
initIndex = 0,
onChange,
...rest
}) => {
let lastSelected = initIndex;
let value = options[initIndex].value;
const widget = Box({
tooltipText: desc,
className: 'segment-container',
// homogeneous: true,
children: options.map((option, id) => {
const selectedIcon = Revealer({
revealChild: id == initIndex,
transition: 'slide_right',
transitionDuration: 150,
child: MaterialIcon('check', 'norm')
});
return Button({
setup: setupCursorHover,
className: `segment-btn ${id == initIndex ? 'segment-btn-enabled' : ''}`,
child: Box({
hpack: 'center',
className: 'spacing-h-5',
children: [
selectedIcon,
Label({
label: option.name,
})
]
}),
onClicked: (self) => {
value = option.value;
const kids = widget.get_children();
kids[lastSelected].toggleClassName('segment-btn-enabled', false);
kids[lastSelected].get_children()[0].get_children()[0].revealChild = false;
lastSelected = id;
self.toggleClassName('segment-btn-enabled', true);
selectedIcon.revealChild = true;
onChange(option.value, option.name);
}
})
}),
...rest,
});
return widget;
}
export const ConfigGap = ({ vertical = true, size = 5, ...rest }) => Box({
className: `gap-${vertical ? 'v' : 'h'}-${size}`,
...rest,
})
+10 -7
View File
@@ -12,12 +12,11 @@ let sub_h1, sub_h2, sub_h3, sub_h4, sub_h5
// m2p_sections defines how to detect special markdown sections.
// These expressions scan the full line to detect headings, lists, and code.
const m2p_sections = [
// h1 is actually 210% on github, but it's unecessary large imo
sub_h1 = { name: H1, re: /^(#\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='150%'>$2</span>" },
sub_h2 = { name: H2, re: /^(##\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='125%'>$2</span>" },
sub_h3 = { name: H3, re: /^(###\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='100%'>$2</span>" },
sub_h4 = { name: H4, re: /^(####\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='90%'>$2</span>" },
sub_h5 = { name: H5, re: /^(#####\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='80%'>$2</span>" },
sub_h1 = { name: H1, re: /^(#\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='170%'>$2</span>" },
sub_h2 = { name: H2, re: /^(##\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='150%'>$2</span>" },
sub_h3 = { name: H3, re: /^(###\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='125%'>$2</span>" },
sub_h4 = { name: H4, re: /^(####\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='100%'>$2</span>" },
sub_h5 = { name: H5, re: /^(#####\s+)(.*)(\s*)$/, sub: "<span font_weight='bold' size='90%'>$2</span>" },
{ name: BULLET, re: /^(\s*)([\*\-]\s)(.*)(\s*)$/, sub: "$1• $3" },
{ name: NUMBERING, re: /^(\s*[0-9]+\.\s)(.*)(\s*)$/, sub: " $1$2" },
]
@@ -226,7 +225,11 @@ if (__is_nodejs_main) {
console.log(`Usage: ${process.argv[1]} FILE [FILE...]`)
process.exit(0)
}
args.forEach((f) => process.stdout.write(convert(readFile(f))))
for (let i = 0; i < args.length; i++) {
const f = args[i];
process.stdout.write(convert(readFile(f)));
}
}
export const markdownTest = `# Heading 1
@@ -50,7 +50,9 @@ else:
# exit()
colorscheme=0
darkmode = True
if("-l" in sys.argv):
darkmode = False
colorscheme = newtheme.get('schemes').get('light')
print('$darkmode: false;')
else:
@@ -85,8 +87,9 @@ inverseSurface = hexFromArgb(colorscheme.get_inverseSurface())
inverseOnSurface = hexFromArgb(colorscheme.get_inverseOnSurface())
inversePrimary = hexFromArgb(colorscheme.get_inversePrimary())
# post proccessing
background = darken(background, 0.6)
# make material less boring
if darkmode:
background = darken(background, 0.6)
print('$primary: ' + primary + ';')
print('$onPrimary: ' + onPrimary + ';')
@@ -87,34 +87,34 @@
"BLACK_500": "#393634",
"BLACK_700": "#33302F",
"BLACK_900": "#2B2928",
"accent_bg_color": "#c4c0ff",
"accent_fg_color": "#251a8c",
"accent_color": "#c4c0ff",
"destructive_bg_color": "#ffb4a9",
"destructive_fg_color": "#680003",
"destructive_color": "#ffb4a9",
"accent_bg_color": "#e2e2e2",
"accent_fg_color": "#000000",
"accent_color": "#e2e2e2",
"destructive_bg_color": "#e2e2e2",
"destructive_fg_color": "#000000",
"destructive_color": "#e2e2e2",
"success_bg_color": "#81C995",
"success_fg_color": "rgba(0, 0, 0, 0.87)",
"warning_bg_color": "#FDD633",
"warning_fg_color": "rgba(0, 0, 0, 0.87)",
"error_bg_color": "#ffb4a9",
"error_fg_color": "#680003",
"window_bg_color": "#101012",
"window_fg_color": "#e5e1e6",
"view_bg_color": "#1c1b1f",
"view_fg_color": "#e5e1e6",
"error_bg_color": "#e2e2e2",
"error_fg_color": "#000000",
"window_bg_color": "#000000",
"window_fg_color": "#e2e2e2",
"view_bg_color": "#000000",
"view_fg_color": "#e2e2e2",
"headerbar_bg_color": "mix(@dialog_bg_color, @window_bg_color, 0.5)",
"headerbar_fg_color": "#e3dff9",
"headerbar_border_color": "#464559",
"headerbar_fg_color": "#e2e2e2",
"headerbar_border_color": "#313131",
"headerbar_backdrop_color": "@headerbar_bg_color",
"headerbar_shade_color": "rgba(0, 0, 0, 0.09)",
"card_bg_color": "#101012",
"card_fg_color": "#e3dff9",
"card_bg_color": "#000000",
"card_fg_color": "#e2e2e2",
"card_shade_color": "rgba(0, 0, 0, 0.09)",
"dialog_bg_color": "#464559",
"dialog_fg_color": "#e3dff9",
"popover_bg_color": "#464559",
"popover_fg_color": "#e3dff9",
"dialog_bg_color": "#313131",
"dialog_fg_color": "#e2e2e2",
"popover_bg_color": "#313131",
"popover_fg_color": "#e2e2e2",
"thumbnail_bg_color": "#1a1b26",
"thumbnail_fg_color": "#AEE5FA",
"shade_color": "rgba(0, 0, 0, 0.36)",
+68 -3
View File
@@ -42,7 +42,7 @@ menu {
-gtk-outline-radius: 1.159rem;
animation-name: appear;
animation-duration: 100ms;
animation-duration: 40ms;
animation-timing-function: ease-out;
animation-iteration-count: 1;
}
@@ -81,12 +81,11 @@ tooltip {
}
.configtoggle-box {
padding: 0.205rem;
padding: 0.205rem 0.341rem;
border: 0.136rem solid transparent;
}
.configtoggle-box:focus {
padding: 0.205rem;
border: 0.136rem solid mix($onSurface, $surface, 40%);
}
@@ -126,4 +125,70 @@ tooltip {
@include menu_decel;
min-width: 1.636rem;
min-height: 0.819rem;
}
.segment-container {
@include full-rounding;
border: 0.068rem solid $outline;
}
.segment-container>*:first-child {
border-top-left-radius: 9999px;
border-bottom-left-radius: 9999px;
}
.segment-container>* {
border-right: 0.068rem solid $outline;
padding: 0.341rem 0.682rem;
}
.segment-container>*:last-child {
border-right: 0rem solid transparent;
border-top-right-radius: 9999px;
border-bottom-right-radius: 9999px;
}
.segment-btn {
color: $onSurface;
}
.segment-btn:focus,
.segment-btn:hover {
background-color: $surfaceVariant;
color: $onSurfaceVariant;
}
.segment-btn-enabled {
background-color: $secondaryContainer;
color: $onSecondaryContainer;
}
.segment-btn-enabled:hover,
.segment-btn-enabled:focus {
background-color: $secondaryContainer;
color: $onSecondaryContainer;
}
.gap-v-5 {
min-height: 0.341rem;
}
.gap-h-5 {
min-width: 0.341rem;
}
.gap-v-10 {
min-height: 0.682rem;
}
.gap-h-10 {
min-width: 0.682rem;
}
.gap-v-15 {
min-height: 1.023rem;
}
.gap-h-15 {
min-width: 1.023rem;
}
+28 -27
View File
@@ -1,29 +1,30 @@
$darkmode: true;
$primary: #c4c0ff;
$onPrimary: #251a8c;
$primaryContainer: #3d36a2;
$onPrimaryContainer: #e3dfff;
$secondary: #c7c4dd;
$onSecondary: #2f2e42;
$secondaryContainer: #464559;
$onSecondaryContainer: #e3dff9;
$tertiary: #eab9d1;
$onTertiary: #472639;
$tertiaryContainer: #603c50;
$onTertiaryContainer: #ffd8eb;
$error: #ffb4a9;
$onError: #680003;
$errorContainer: #930006;
$onErrorContainer: #ffb4a9;
$colorbarbg: #101012;
$background: #101012;
$onBackground: #e5e1e6;
$surface: #1c1b1f;
$onSurface: #e5e1e6;
$surfaceVariant: #47464f;
$onSurfaceVariant: #c8c5d0;
$outline: #928f9a;
$primary: #e2e2e2;
$onPrimary: #000000;
$primaryContainer: #6b6b6b;
$onPrimaryContainer: #e2e2e2;
$secondary: #e2e2e2;
$onSecondary: #000000;
$secondaryContainer: #313131;
$onSecondaryContainer: #e2e2e2;
$tertiary: #e2e2e2;
$onTertiary: #000000;
$tertiaryContainer: #000000;
$onTertiaryContainer: #e2e2e2;
$error: #e2e2e2;
$onError: #000000;
$errorContainer: #000000;
$onErrorContainer: #e2e2e2;
$colorbarbg: #000000;
$background: #000000;
$onBackground: #e2e2e2;
$surface: #000000;
$onSurface: #e2e2e2;
$surfaceVariant: #202020;
$onSurfaceVariant: #e2e2e2;
$outline: #a1a1a1;
$shadow: #000000;
$inverseSurface: #e5e1e6;
$inverseOnSurface: #313033;
$inversePrimary: #5550bb;
$inverseSurface: #e2e2e2;
$inverseOnSurface: #000000;
$inversePrimary: #e2e2e2;
+3 -3
View File
@@ -12,7 +12,7 @@ $onChatgpt: $onPrimary;
@include menu_decel;
@include elevation-border;
@include elevation2;
border-radius: $rounding_large - $elevation_margin;
border-radius: $rounding_large - $elevation_margin + 0.068rem;
min-width: 27.818rem; // COMMENT THIS LATER IF TEXT WRAP IS USED
// min-height: 29.591rem;
background-color: $t_background;
@@ -33,7 +33,7 @@ $onChatgpt: $onPrimary;
@include menu_decel;
@include elevation-border;
@include elevation2;
border-radius: $rounding_large - $elevation_margin;
border-radius: $rounding_large - $elevation_margin + 0.068rem;
min-width: 27.818rem; // COMMENT THIS LATER IF TEXT WRAP IS USED
// min-height: 29.591rem;
background-color: $t_background;
@@ -645,7 +645,7 @@ $onChatgpt: $onPrimary;
margin: 0rem 3.409rem;
}
.sidebar-chat-settings {
.sidebar-chat-settings-toggles {
margin: 0rem 5.455rem;
}
+6
View File
@@ -121,6 +121,7 @@ class ChatGPTService extends Service {
_assistantPrompt = false;
_messages = [];
_cycleModels = true;
_temperature = 0.5;
_requestCount = 0;
_modelIndex = 0;
_key = '';
@@ -159,6 +160,9 @@ class ChatGPTService extends Service {
}
}
get temperature() { return this._temperature }
set temperature(value) { this._temperature = value; }
get messages() { return this._messages }
get lastMessage() { return this._messages[this._messages.length - 1] }
@@ -218,6 +222,8 @@ class ChatGPTService extends Service {
const body = {
model: CHAT_MODELS[this._modelIndex],
messages: this._messages.map(msg => { let m = { role: msg.role, content: msg.content }; return m; }),
temperature: this._temperature,
// temperature: 2, // <- Nuts
stream: true,
};
+409 -357
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -123,7 +123,7 @@ const BarBattery = () => {
['fallback', memUsage],
['battery', batteryWidget],
],
setup: (stack) => Utils.timeout(1, () => {
setup: (stack) => Utils.timeout(1, () => { // On desktops systems with no battery, show memory usage instead
if (Battery.available) stack.shown = 'battery';
else stack.shown = 'fallback';
})
@@ -134,6 +134,7 @@ const BarBattery = () => {
export const ModuleSystem = () => Widget.EventBox({
onScrollUp: () => execAsync('hyprctl dispatch workspace -1'),
onScrollDown: () => execAsync('hyprctl dispatch workspace +1'),
onPrimaryClick: () => App.toggleWindow('sideright'),
child: Widget.Box({
className: 'bar-group-margin bar-sides',
children: [
+4 -2
View File
@@ -74,12 +74,14 @@ export const ModuleWorkspaces = () => Widget.EventBox({
[Hyprland, (box) => {
// console.log('update');
const kids = box.children;
kids.forEach((child, i) => {
for (let i = 0; i < kids.length; i++) {
const child = kids[i];
child.child.toggleClassName('bar-ws-occupied', false);
child.child.toggleClassName('bar-ws-occupied-left', false);
child.child.toggleClassName('bar-ws-occupied-right', false);
child.child.toggleClassName('bar-ws-occupied-left-right', false);
});
}
const occupied = Array.from({ length: NUM_OF_WORKSPACES }, (_, i) => Hyprland.getWorkspace(i + 1)?.windows > 0);
for (let i = 0; i < occupied.length; i++) {
if (!occupied[i]) continue;
@@ -138,10 +138,12 @@ export default () => Box({
}),
onPrimaryClickRelease: () => {
const kids = resources.get_children();
kids.forEach((child, i) => {
child.get_children()[0].revealChild = !child.get_children()[0].revealChild;
});
for (let i = 0; i < kids.length; i++) {
const child = kids[i];
const firstChild = child.get_children()[0];
firstChild.revealChild = !firstChild.revealChild;
}
},
})
],
+3 -2
View File
@@ -86,7 +86,8 @@ const Taskbar = () => Widget.Box({
return a._workspace > b._workspace;
}],
['update', (box) => {
Hyprland.clients.forEach(client => {
for (let i = 0; i < Hyprland.clients.length; i++) {
const client = Hyprland.clients[i];
if (client["pid"] == -1) return;
const appClass = substitute(client.class);
for (const appName of pinnedApps) {
@@ -101,7 +102,7 @@ const Taskbar = () => Widget.Box({
newButton._workspace = client.workspace.id;
newButton.revealChild = true;
box._map.set(client.address, newButton);
})
}
box.children = Array.from(box._map.values());
}],
['add', (box, address) => {
@@ -360,7 +360,11 @@ export default () => Widget.Revealer({
if (!foundPlayer) {
box._player = null;
box.get_children().forEach(ch => ch.destroy());
const children = box.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
return;
}
}, 'notify::players']],
+28 -6
View File
@@ -257,7 +257,7 @@ const workspace = index => {
child: fixed,
})],
});
widget.update = clients => {
widget.update = (clients) => {
clients = clients.filter(({ workspace: { id } }) => id === index);
// this is for my monitor layout
@@ -269,9 +269,22 @@ const workspace = index => {
return client;
});
fixed.get_children().forEach(ch => ch.destroy());
const children = fixed.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
fixed.put(WorkspaceNumber(index), 0, 0);
clients.forEach(c => c.mapped && fixed.put(client(c), c.at[0] * OVERVIEW_SCALE, c.at[1] * OVERVIEW_SCALE));
for (let i = 0; i < clients.length; i++) {
const c = clients[i];
if (c.mapped) {
fixed.put(client(c), c.at[0] * OVERVIEW_SCALE, c.at[1] * OVERVIEW_SCALE);
}
}
fixed.show_all();
};
return widget;
@@ -290,7 +303,12 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
properties: [['update', box => {
execAsync('hyprctl -j clients').then(clients => {
const json = JSON.parse(clients);
box.get_children().forEach(ch => ch.update(json));
const children = box.get_children();
for (let i = 0; i < children.length; i++) {
const ch = children[i];
ch.update(json)
}
}).catch(print);
}]],
setup: (box) => box._update(box),
@@ -375,7 +393,7 @@ export const SearchAndWindows = () => {
hpack: 'center',
onAccept: (self) => { // This is when you hit Enter
const text = self.text;
if(text.length == 0) return;
if (text.length == 0) return;
const isAction = text.startsWith('>');
const isDir = (entry.text[0] == '/' || entry.text[0] == '~');
@@ -423,7 +441,11 @@ export const SearchAndWindows = () => {
['notify::text', (entry) => { // This is when you type
const isAction = entry.text[0] == '>';
const isDir = (entry.text[0] == '/' || entry.text[0] == '~');
resultsBox.get_children().forEach(ch => ch.destroy());
const children = resultsBox.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
// check empty if so then dont do stuff
if (entry.text == '') {
resultsRevealer.set_reveal_child(false);
+77 -41
View File
@@ -6,7 +6,7 @@ import ChatGPT from '../../../services/chatgpt.js';
import { MaterialIcon } from "../../../lib/materialicon.js";
import { setupCursorHover, setupCursorHoverInfo } from "../../../lib/cursorhover.js";
import { SystemMessage, ChatMessage } from "./chatgpt_chatmessage.js";
import { ConfigToggle } from '../../../lib/configwidgets.js';
import { ConfigToggle, ConfigSegmentedSelection, ConfigGap } from '../../../lib/configwidgets.js';
import { markdownTest } from '../../../lib/md2pango.js';
const chatGPTTabIcon = Icon({
@@ -68,36 +68,58 @@ export const chatGPTSettings = Revealer({
transitionDuration: 150,
revealChild: true,
connections: [
[ChatGPT, (self) => {
[ChatGPT, (self) => Utils.timeout(200, () => {
self.revealChild = false;
}, 'newMsg'],
[ChatGPT, (self) => {
}), 'newMsg'],
[ChatGPT, (self) => Utils.timeout(200, () => {
self.revealChild = true;
}, 'clear'],
}), 'clear'],
],
child: Box({
vertical: true,
hpack: 'fill',
className: 'sidebar-chat-settings',
children: [
ConfigToggle({
icon: 'cycle',
name: 'Cycle models',
desc: 'Helps avoid exceeding the API rate of 3 messages per minute.\nTurn this on if you message rapidly.',
initValue: ChatGPT.cycleModels,
onChange: (self, newValue) => {
ChatGPT.cycleModels = newValue;
},
}),
ConfigToggle({
icon: 'description',
name: 'Assistant prompt',
desc: 'Tells ChatGPT\n 1. It\'s a sidebar assistant on Linux\n 2. Be short and concise\n 3. Use markdown features extensively\nLeave this off for a vanilla ChatGPT experience.',
initValue: ChatGPT.assistantPrompt,
onChange: (self, newValue) => {
ChatGPT.assistantPrompt = newValue;
ConfigSegmentedSelection({
hpack: 'center',
icon: 'casino',
name: 'Randomness',
desc: 'ChatGPT\'s temperature value.\n Precise = 0\n Balanced = 0.5\n Creative = 1',
options: [
{ value: 0.00, name: 'Precise', },
{ value: 0.50, name: 'Balanced', },
{ value: 1.00, name: 'Creative', },
],
initIndex: 1,
onChange: (value, name) => {
ChatGPT.temperature = value;
},
}),
ConfigGap({ vertical: true, size: 10 }), // Note: size can only be 5, 10, or 15
Box({
vertical: true,
hpack: 'fill',
className: 'sidebar-chat-settings-toggles',
children: [
ConfigToggle({
icon: 'cycle',
name: 'Cycle models',
desc: 'Helps avoid exceeding the API rate of 3 messages per minute.\nTurn this on if you message rapidly.',
initValue: ChatGPT.cycleModels,
onChange: (self, newValue) => {
ChatGPT.cycleModels = newValue;
},
}),
ConfigToggle({
icon: 'description',
name: 'Assistant prompt',
desc: 'Tells ChatGPT\n 1. It\'s a sidebar assistant on Linux\n 2. Be short and concise\n 3. Use markdown features extensively\nLeave this off for a vanilla ChatGPT experience.',
initValue: ChatGPT.assistantPrompt,
onChange: (self, newValue) => {
ChatGPT.assistantPrompt = newValue;
},
}),
]
})
]
})
});
@@ -136,7 +158,7 @@ export const chatGPTWelcome = Box({
children: [
chatGPTInfo,
openaiApiKeyInstructions,
chatGPTSettings,
chatGPTSettings, ``
]
})
});
@@ -148,21 +170,30 @@ export const chatContent = Box({
[ChatGPT, (box, id) => {
const message = ChatGPT.messages[id];
if (!message) return;
box.add(ChatMessage(message))
box.add(ChatMessage(message, chatGPTView))
}, 'newMsg'],
[ChatGPT, (box) => {
box.children = [chatGPTWelcome];
}, 'clear'],
[ChatGPT, (box) => {
box.children = [chatGPTWelcome];
}, 'initialized'],
]
});
const clearChat = () => {
ChatGPT.clear();
const children = chatContent.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
}
export const chatGPTView = Scrollable({
className: 'sidebar-chat-viewport',
vexpand: true,
child: chatContent,
child: Box({
vertical: true,
children: [
chatGPTWelcome,
chatContent,
]
}),
setup: (scrolledWindow) => {
scrolledWindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
const vScrollbar = scrolledWindow.get_vscrollbar();
@@ -183,7 +214,8 @@ export const chatGPTCommands = Box({
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
onClicked: () => chatContent.add(SystemMessage(
`Key stored in:\n\`${ChatGPT.keyPath}\`\nTo update this key, type \`/key YOUR_API_KEY\``,
'/key')),
'/key',
chatGPTView)),
setup: setupCursorHover,
label: '/key',
}),
@@ -191,14 +223,15 @@ export const chatGPTCommands = Box({
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
onClicked: () => chatContent.add(SystemMessage(
`Currently using \`${ChatGPT.modelName}\``,
'/model'
'/model',
chatGPTView
)),
setup: setupCursorHover,
label: '/model',
}),
Button({
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
onClicked: () => ChatGPT.clear(),
onClicked: () => clearChat(),
setup: setupCursorHover,
label: '/clear',
}),
@@ -210,26 +243,29 @@ export const chatGPTSendMessage = (text) => {
if (text.length == 0) return;
if (ChatGPT.key.length == 0) {
ChatGPT.key = text;
chatContent.add(SystemMessage(`Key saved to\n\`${ChatGPT.keyPath}\``, 'API Key'));
chatContent.add(SystemMessage(`Key saved to\n\`${ChatGPT.keyPath}\``, 'API Key', chatGPTView));
text = '';
return;
}
// Commands
if (text.startsWith('/')) {
if (text.startsWith('/clear')) ChatGPT.clear();
else if (text.startsWith('/model')) chatContent.add(SystemMessage(`Currently using \`${ChatGPT.modelName}\``, '/model'))
if (text.startsWith('/clear')) clearChat();
else if (text.startsWith('/model')) chatContent.add(SystemMessage(`Currently using \`${ChatGPT.modelName}\``, '/model', chatGPTView))
else if (text.startsWith('/key')) {
const parts = text.split(' ');
if (parts.length == 1) chatContent.add(SystemMessage(`Key stored in:\n\`${ChatGPT.keyPath}\`\nTo update this key, type \`/key YOUR_API_KEY\``, '/key'));
if (parts.length == 1) chatContent.add(SystemMessage(
`Key stored in:\n\`${ChatGPT.keyPath}\`\nTo update this key, type \`/key YOUR_API_KEY\``,
'/key',
chatGPTView));
else {
ChatGPT.key = parts[1];
chatContent.add(SystemMessage(`Updated API Key at\n\`${ChatGPT.keyPath}\``, '/key'));
chatContent.add(SystemMessage(`Updated API Key at\n\`${ChatGPT.keyPath}\``, '/key', chatGPTView));
}
}
else if (text.startsWith('/test'))
chatContent.add(SystemMessage(markdownTest, `Markdown test`));
chatContent.add(SystemMessage(markdownTest, `Markdown test`, chatGPTView));
else
chatContent.add(SystemMessage(`Invalid command.`, 'Error'))
chatContent.add(SystemMessage(`Invalid command.`, 'Error', chatGPTView))
}
else {
ChatGPT.send(text);
@@ -148,7 +148,11 @@ const MessageContent = (content) => {
properties: [
['fullUpdate', (self, content, useCursor = false) => {
// Clear and add first text widget
contentBox.get_children().forEach(ch => ch.destroy());
const children = contentBox.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
contentBox.add(TextBlock())
// Loop lines. Put normal text in markdown parser
// and put code into code highlighter (TODO)
@@ -214,7 +218,7 @@ const MessageContent = (content) => {
return contentBox;
}
export const ChatMessage = (message) => {
export const ChatMessage = (message, scrolledWindow) => {
const messageContentBox = MessageContent(message.content);
const thisMessage = Box({
className: 'sidebar-chat-message',
@@ -243,7 +247,7 @@ export const ChatMessage = (message) => {
[message, (self) => { // Message update
messageContentBox._fullUpdate(messageContentBox, message.content, message.role != 'user');
Utils.timeout(MESSAGE_SCROLL_DELAY, () => {
const scrolledWindow = thisMessage.get_parent().get_parent();
if (!scrolledWindow) return;
var adjustment = scrolledWindow.get_vadjustment();
adjustment.set_value(adjustment.get_upper() - adjustment.get_page_size());
});
@@ -258,7 +262,7 @@ export const ChatMessage = (message) => {
return thisMessage;
}
export const SystemMessage = (content, commandName) => {
export const SystemMessage = (content, commandName, scrolledWindow) => {
const messageContentBox = MessageContent(content);
const thisMessage = Box({
className: 'sidebar-chat-message',
@@ -282,7 +286,7 @@ export const SystemMessage = (content, commandName) => {
})
],
setup: (self) => Utils.timeout(MESSAGE_SCROLL_DELAY, () => {
const scrolledWindow = thisMessage.get_parent().get_parent();
if (!scrolledWindow) return;
var adjustment = scrolledWindow.get_vadjustment();
adjustment.set_value(adjustment.get_upper() - adjustment.get_page_size());
})
+3
View File
@@ -18,6 +18,9 @@ export const SidebarModule = ({
className: 'txt-small txt',
label: `${name}`,
}),
Box({
hexpand: true,
}),
Label({
className: 'sidebar-module-btn-arrow',
})
@@ -7,6 +7,5 @@ import { SidebarModule } from './module.js';
export const QuickScripts = () => SidebarModule({
name: 'Quick scripts',
child: Box({
})
})
@@ -65,6 +65,11 @@ const CalendarWidget = () => {
}
});
const addCalendarChildren = (box, calendarJson) => {
const children = box.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.destroy();
}
box.children = calendarJson.map((row, i) => Widget.Box({
// homogeneous: true,
className: 'spacing-h-5',
+7 -7
View File
@@ -41,18 +41,18 @@ import { ModuleCalendar } from "./calendar.js";
const timeRow = Box({
className: 'spacing-h-5 sidebar-group-invisible-morehorizpad',
children: [
Widget.Label({
className: 'txt-title txt',
connections: [[5000, label => {
label.label = GLib.DateTime.new_now_local().format("%H:%M");
}]],
}),
// Widget.Label({
// className: 'txt-title txt',
// connections: [[5000, label => {
// label.label = GLib.DateTime.new_now_local().format("%H:%M");
// }]],
// }),
Widget.Label({
hpack: 'center',
className: 'txt-small txt',
connections: [[5000, label => {
execAsync(['bash', '-c', `uptime -p | sed -e 's/up //;s/ hours,/h/;s/ minutes/m/'`]).then(upTimeString => {
label.label = `• up: ${upTimeString}`;
label.label = `System uptime: ${upTimeString}`;
}).catch(print);
}]],
}),