SQLite User Forum

Feature request: longer prompts
Login

Feature request: longer prompts

(1) By Peter Oliver (mavit.org.uk) on 2025-02-17 10:51:21 [source]

I find that the longest prompt I can set with the .prompt command is 18 characters; anything longer is truncated. There are a couple of things I would like to do, that this prevents.

I would like to be able to change the colour of the prompt, so that it stands out relative to the rest of the text on my terminal. However, the control characters required to do this use up most of the 18, leaving too few for the actual prompt.

I would like to use a shell alias to automatically put the database name in the prompt (so, something along the lines of sqlite3 -cmd ".prompt 'filename.db> ' /path/to/filename.db), without worrying that this might become garbled if the filename is too long.

(2) By Kees Nuyt (knu) on 2025-02-17 12:22:43 in reply to 1 [link] [source]

You can easily change the source and recompile:

cd ~/src/sqlite  # or wherever your sqlite source tree is
make clean
sed -i -e 's/define PROMPT_LEN_MAX 20/define PROMPT_LEN_MAX 80/' src/shell.c.in 
make sqlite3

Then this works:

./sqlite3 /home/developer/var/mydatabase.sqlite
.prompt '/home/developer/var/mydatabase.sqlite> ' ' ..> '

(3) By Aask (AAsk1902) on 2025-02-17 17:30:57 in reply to 1 [link] [source]

If you are using Windows, one option is to make the database name the CLI's caption, thus:

.shell title I am using this.db

This is a manual process that would need to be repeaed everytime you .open another database in the same session.

(4) By Mike Castle (nexushoratio) on 2025-02-17 18:19:51 in reply to 3 [link] [source]

The same "manual process" caveat applies to updating the prompt to show the filename.

Similar window title setting can be done with most Unix based terminal emulators as well. However, I suspect, that in all OSes, putting the window in full screen mode would likely hide such a title.

Anyway, I traced the origin of the 20-char limit as far back as 2002-04-18 with https://www.sqlite.org/src/info/e751338c468cdad7 (prior to that, they were inline hard-coded strings)

23 years later, is 20 chars still appropriate for an out-of-the-box experience, or can the default be made longer without requiring a local recompile?

(5) By Kees Nuyt (knu) on 2025-02-17 23:35:30 in reply to 4 [link] [source]

or can the default be made longer without requiring a local recompile?

A recompile is necessary, because the prompt is in static memory, with a predefined size.

See the shell source

(8) By Mike Castle (nexushoratio) on 2025-02-18 19:54:14 in reply to 5 [link] [source]

Sorry, that was meant as a question about updating that exact line of source to be longer out-of-box (thus, "without requiring a local recompile").

Of course, there is also always the option of replacing the use of static memory with allocated at startup (and reallocated if the user wants a longer prompt).

(6) By Stephan Beal (stephan) on 2025-02-18 00:46:11 in reply to 4 [link] [source]

23 years later, is 20 chars still appropriate for an out-of-the-box experience, or can the default be made longer without requiring a local recompile?

FWIW, i've marked this thread in my inbox as to-revisit after the imminent 3.49.1 patch release is made. A quick test of extending that buffer to 128 bytes didn't reveal any weirdness (my initial concern was that it would interfere with the continuation marker, but it doesn't).

A very long prompt is probably going to want to include a newline at the end, else it gets awkward to have the input start at the mid-point of the console:

sqlite> .prompt '/home/stephan/f/s/lite/foo/bar/baz.db > '
/home/stephan/f/s/lite/foo/bar/baz.db > select
   ...> 1
   ...> from sqlite_schema
   ...> ;
/home/stephan/f/s/lite/foo/bar/baz.db > 

Awkward. Adding a newline would require that the .prompt command parse \n as a newline escape sequence.

Alternatively, we could move the continuation prompt appropriately far to the right, but that would possibly be even more awkward and would require a larger change than simply extending that buffer size does.

(7) By Peter Oliver (mavit.org.uk) on 2025-02-18 16:32:22 in reply to 6 [link] [source]

Adding a newline would require that the .prompt command parse \n as a newline escape sequence.

A workaround for this is to pass the newline in with the -cmd option. Example with the Bash shell:

sqlite3 -cmd '.prompt "sqlite
> "' example.db

(9) By Stephan Beal (stephan) on 2025-02-19 13:08:08 in reply to 4 [link] [source]

23 years later, is 20 chars still appropriate for an out-of-the-box experience, or can the default be made longer without requiring a local recompile?

This is now set to 128 bytes in the current trunk. It would be interesting to make the size dynamic and to be able to handle escaped \n characters so that long prompts can end with one (see my previous response for why), but that would require a much more significant change. That hasn't been ruled out as an eventuality, but has been ruled out for today.