Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
more like "you can and should have libraries but you don't need libavif to support avif because something outside your program somehow turns them into stuff your program knows how to work with"
Still kind of broad strokes though I don't expect a detailed technical document from you right now, of course. I can think of past (and, in some ways, still present) exemplars of multimedia computing that may ring a bell: Amiga, NeXTSTEP and BeOS (now Haiku OS). For example, in the Unix Haters' Handbook it talks about how much better NeXTSTEP's Display PostScript system is than X Windows, and I believe OS X uses something quite similar:
Screenshot 2025-06-20 at 21-32-44 ugh.book - ugh.pdf.webp
Any of this sound appealing?
 
Still kind of broad strokes though I don't expect a detailed technical document from you right now, of course. I can think of past (and, in some ways, still present) exemplars of multimedia computing that may ring a bell: Amiga, NeXTSTEP and BeOS (now Haiku OS). For example, in the Unix Haters' Handbook it talks about how much better NeXTSTEP's Display PostScript system is than X Windows, and I believe OS X uses something quite similar:
View attachment 7534152
Any of this sound appealing?
that's just some ui sperging, i'm thinking more about something sort of like translators as seen in the gnu hurd
and it's likely that such a thing could be used in a window system if it was a file system too
 
I'm not too familiar. How close are we to the Year of the GNU/Hurd Desktop?
translators are like linux fuse on steroids and all of the filesystems in the hurd are implemented as programs that run in userspace
afaik we are still extremely far from the year of the hurd desktop though since the retard penguin monokernel was finished first and it's not that much worse than the hurd
 
  • Feels
Reactions: Belisarius Cawl
I'm not too familiar. How close are we to the Year of the GNU/Hurd Desktop?
Soon.

And the translation thing could be implemented in FUSE. There's already simple ones to treat zip files as directories. Could have a translation table that says "when less opens a .doc, send it text" although less already has similar functionality built in. Or maybe every PDF is a directory and you could open myfile.pdf/7/png if you want page 7 as a png.
 
Soon.

And the translation thing could be implemented in FUSE. There's already simple ones to treat zip files as directories. Could have a translation table that says "when less opens a .doc, send it text" although less already has similar functionality built in. Or maybe every PDF is a directory and you could open myfile.pdf/7/png if you want page 7 as a png.
I was recently wondering how X implements multimedia copy/paste. IIRC it's good ol' text but with a MIME type prepended.
 
  • Feels
Reactions: DavidS877
I was recently wondering how X implements multimedia copy/paste. IIRC it's good ol' text but with a MIME type prepended.
x11 itself actually doesn't specify anything at all about copying and pasting so your application has to follow a bunch of conventions to work properly in modern window managers without things like drag and drop or the clipboard failing spectacularly
so there is this hilarious document that explains how to do these things
anyway this section has a list of types that x11 has by default, but it says that it's extensible so most clients will use mime types too
i actually don't completely understand how it works because i'm not enough of a wizard but i can say that it's rather niggerlicious (credit where it's due, it works a lot of the time though)
 
havent posted in a minute since development went from adding new features every 3 or so days to well heres a better way to organize/compartmentalize/encapsulate this function. in the state it is now i cant redily post it as a single block since its been split into different files but the main file now looks like this:
Python:
import curses
import sys
import os
from dataclasses import dataclass, field
from Core import save_file, load_file, Cursor, visual_cursor_renderer
from UI import StatusWindow, ContentBufferWindow, CommandBox, WindowManager
# Shortcut Dictionary
shortcutKeys={}
#SETUP
#NOTE Will go in its own file eventually.
def screen_setup(stdscr):
    curses.raw()
    curses.noecho()
    stdscr.keypad(1)

def screen_initialiser(stdscr):
    term_row, term_column = stdscr.getmaxyx()
    buffer = []
    src  =sys.argv[1] if len(sys.argv)==2 else 'noname.txt'
    cursor = Cursor(buffer=buffer)
    load_file(buffer= buffer, filepath= src)
    return term_row, term_column, buffer, src, cursor

#MAIN
def main(stdscr):
    # Initialize the screen
    mainscreen = stdscr 
    screen_setup(stdscr=mainscreen)
    term_row, term_column, buffer, src, cursor =screen_initialiser(stdscr=mainscreen)

    window_manager = WindowManager(buffer= buffer, cursor= cursor, width= term_column, height = term_row, src= src)
    
    while True:
        mainscreen.move(0,0)   #positions the cursor to top left
        #SCROLLING
        cursor.cursor_scrolling(term_column=term_column, visible_rows= window_manager.content.height)

        #SCREEN RENDERING
        window_manager.render()

        #CURSOR RENDERING
        visual_cursor_renderer(screen=mainscreen, cursor = cursor)       

        #input manager
        ch =mainscreen.getch()

        #Text insert   
        if ch != ((ch) & 0x1f) and ch < 128:
            buffer[cursor.row].insert(cursor.column, ch)
            cursor.column +=1

        #enter handling   
        if chr(ch) in "\n\r":
            line = buffer[cursor.row][cursor.column:]
            buffer[cursor.row] = buffer[cursor.row][:cursor.column]
            cursor.row+=1
            cursor.column = 0
            buffer.insert(cursor.row, line)
        
        #Backspace handling
        if ch in [8,263]:
            if cursor.column:
                try:
                    cursor.column -=1
                    del buffer[cursor.row][cursor.column]
                except IndexError:
                    cursor.column = len(cursor.buffer[cursor.row])

            elif cursor.row>0:
                line = buffer[cursor.row][cursor.column:]
                del buffer[cursor.row]
                cursor.row -=1
                cursor.column = len(buffer[cursor.row])
                buffer[cursor.row] += line

        #CURSOR ACTIONS     
        cursor.cursor_actions(ch=ch)

        #save and quit
        if ch == (ord("s") & 0x1f):  # Ctrl+S
            save_file(buffer=buffer, filepath=src)
        if ch == (ord("q") & 0x1f):  # Ctrl+Q
            sys.exit()

curses.wrapper(main) #this protects the terminal

which is a far cry from where i was a month ago. at this point i just need to clean up the set up and input handling then its time to start adding cooler stuff. (i still dont have a compy paste stack, tab, home, end or any other typical shortcuts.)
this is what it currently looks like:
1750737659475.webp
its been interesting working n this project to say the least and im sure it'll keep getting better
 
Generally speaking, if a function or method can't fully fit on the screen, it may be too large
many exceptions exist; the only true way to know if a function is too large is if it does more than one thing and you can prove that the things it does are truly impossible to separate
sometimes something is actually really complicated and it will end up dragging on for more than one screen but i wouldn't say that means you should split it into some absolute shit like doIncrediblyComplexThing4

of course if you have a function that big there's a good possibility you could be attacking the problem from a completely retarded angle, and often it is a sign of retardation
other times it's not really too bad, like if you need a really big switch statement for a main loop that dispatches cleanly to many different functions that call further into your application logic
i know you said "generally speaking" and "may" but i just wanted to elaborate further with a very big "it depends"
 
im at a bit of an impasse currently. when i start my editor nothing happens until an input is recieved because of getch() blocking the rest of the code. now the only way i know how. to resolve this is with the busy wait i had before but that causes a whole host of other issues as was explained to me initially. ive asked chat gpt about it but it's been entirely unhelpful.
Edit: to clarify nothing initially gets rendered to the screen until an input is recieved


Python:
import curses
import sys
import os
import time
from texteditor import screen_initialiser, screen_setup
from dataclasses import dataclass, field
from Core import save_file, load_file, Cursor, visual_cursor_renderer
from UI import StatusWindow, ContentBufferWindow, CommandBox, WindowManager

# Shortcut Dictionary
shortcutKeys={}

def input_handler(character, cursor, buffer):
    #Text insert 
        if character != ((character) & 0x1f) and character < 128:
            buffer[cursor.row].insert(cursor.column, character)
            cursor.column +=1

        #enter handling 
        if chr(character) in "\n\r":
            line = buffer[cursor.row][cursor.column:]
            buffer[cursor.row] = buffer[cursor.row][:cursor.column]
            cursor.row+=1
            cursor.column = 0
            buffer.insert(cursor.row, line)
      
        #Backspace handling
        if character in [8,263]:
            if cursor.column:
                try:
                    cursor.column -=1
                    del buffer[cursor.row][cursor.column]
                except IndexError:
                    cursor.column = len(cursor.buffer[cursor.row])

            elif cursor.row>0:
                line = buffer[cursor.row][cursor.column:]
                del buffer[cursor.row]
                cursor.row -=1
                cursor.column = len(buffer[cursor.row])
                buffer[cursor.row] += line

        #CURSOR ACTIONS   
        cursor.cursor_actions(character)

#MAIN
def main(stdscr):
    # INITITIALISING TERMINAL
    mainscreen = stdscr
    screen_setup(stdscr=mainscreen)
    term_row, term_column, buffer, src, cursor =screen_initialiser(stdscr=mainscreen)
    window_manager = WindowManager(buffer= buffer, cursor= cursor, width= term_column, height = term_row, src= src)
  
  
    while True:
        #INITIAL RENDERING
        cursor.cursor_scrolling(term_column=term_column, visible_rows= window_manager.content.height)#Scrolling
        window_manager.render()#Screen Rendering
        visual_cursor_renderer(screen=mainscreen, cursor = cursor)#Cursor Rendering

      
      
      
      
        ch =mainscreen.getch()
        #INPUT MANAGER
        input_handler(character= ch, buffer=buffer, cursor=cursor)

    
        #save and quit
        if ch == (ord("s") & 0x1f):  # Ctrl+S
            save_file(buffer=buffer, filepath=src)
        if ch == (ord("q") & 0x1f):  # Ctrl+Q
            sys.exit()

curses.wrapper(main) #this protects the terminal
 
  • Feels
Reactions: Belisarius Cawl
  • Thunk-Provoking
Reactions: Marvin
many exceptions exist; the only true way to know if a function is too large is if it does more than one thing and you can prove that the things it does are truly impossible to separate
sometimes something is actually really complicated and it will end up dragging on for more than one screen but i wouldn't say that means you should split it into some absolute shit like doIncrediblyComplexThing4

of course if you have a function that big there's a good possibility you could be attacking the problem from a completely retarded angle, and often it is a sign of retardation
other times it's not really too bad, like if you need a really big switch statement for a main loop that dispatches cleanly to many different functions that call further into your application logic
i know you said "generally speaking" and "may" but i just wanted to elaborate further with a very big "it depends"
I like this post. I think there's many right ways to write code and everyone might draw their lines differently, but whatever you prefer, I think it's beneficial to try to phrase out to yourself what your specific rules are, and try to have ones that are objective enough that they don't require any subjective interpretation, because otherwise you'll find yourself answering the same problem two different ways depending on how you feel.

As you say, there's plenty of times like that where you might think "this function is getting pretty big" but then you comb it over and realize it's not violating SRP or anything, and yeah, some functions just need to be large. I started feeling better about myself when I realized I was considering things tangibly enough to be able to push back at my gut on things like that - having a robust-enough internal rubric to understand that even if something seems off, it's still compliant and there's no more immediately logical way to build it makes me feel really good because it shows I understand my code and also that my project's code has a strong enough sense of "voice" that writing it in a compliant and consistent way is now easier and more intuitive than just hamhandedly hacking out whatever comes to mind.

Coding is fun and it's satisfying to build a little orderly world of logic where everything is in its place.
 
to clarify nothing initially gets rendered to the screen until an input is recieved
i would try looking in the documentation for some sort of ncurses function that flushes the i/o to the screen
then you just have to draw and flush before the program starts waiting for user input
 
Back