Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unix like command history to the Tasmota web console #8015

Closed
scottchiefbaker opened this issue Mar 28, 2020 · 18 comments
Closed

Add a unix like command history to the Tasmota web console #8015

scottchiefbaker opened this issue Mar 28, 2020 · 18 comments
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended

Comments

@scottchiefbaker
Copy link

Have you looked for this feature in other issues and in the docs?

Yes. The only reference I found was issue #7483. I believe we can work around the limitations presented in that issue.

Is your feature request related to a problem? Please describe.

No

Describe the solution you'd like

I'm used to hitting the up arrow to scroll through the command history of my Linux terminal. The Tasmota web console doesn't support this, and it can be problematic. If I'm running status 8 over and over to check a switch it would be very helpful to be able to just hit the up arrow and enter to run the last command.

Describe alternatives you've considered

Copy and paste the same command every time... Limited in that it only stores the last command you ran, and may get overwritten if you use your system for other things.

Additional context

I have written the requisite JavaScript to enable this feature on the web console. You can test this out without modifying your Tasmota installation by navigating to the Tasmota web console and copy and pasting the script below in to your browser's web console.

https://www.perturb.org/code/tasmota_command_history.js

To enable this on Tasmota would simply require including the above Javascript in the <script> tag on the web console page.

Uncompressed/unminified the code is 1077 bytes. Running the code through JSCompress yields a final size of 471 bytes. I suspect I could save more bytes too if I shortened some variable names, but I have not done that yet. If this code is something you're interested in I can work on shrinking the code even further.

(Please, remember to close the issue when the problem has been addressed)

@nagyrobi
Copy link
Contributor

+1 for this

@scottchiefbaker
Copy link
Author

scottchiefbaker commented Mar 28, 2020

Just for my own education I wanted to see how small I could get the code. After renaming some variables and functions I'm able to get the code down to 324 bytes.

@s-hadinger
Copy link
Collaborator

I believe I could use that too. Can you submit a Pull Request with the 324 bytes version?

@effelle effelle added Awaiting feedback from Project Owner Awaiting feedback / input from Project Owner enhancement Type - Enhancement that will be worked on labels Mar 28, 2020
@effelle
Copy link
Contributor

effelle commented Mar 28, 2020

And this has sparked interest in me... Cool one.

@scottchiefbaker
Copy link
Author

I'm not sure how/where in the Tasmota code the Javascript would be inserted. If you can provide that starting point I can investigate.

It may just be easier for someone already familiar with the code base to add in this code.

@scottchiefbaker
Copy link
Author

scottchiefbaker commented Mar 28, 2020

I didn't see you already had a querySelector() alias... using that I can get the code down to 304 bytes.

@effelle
Copy link
Contributor

effelle commented Mar 28, 2020

A smaller code has more probability to be included on firmware, now focus on it and reduce it to no more than 99 bytes. 😄
Just kidding...

@scottchiefbaker
Copy link
Author

Did a little more work and got it down to 266 bytes... anything beyond that and the code won't be readable and hard to maintain.

Before I go too much farther I'd like people to test what I have so far to see if it does what people want. Please copy/paste this minified javascript in to your browser's web console (hit F12). Then enter some commands and hit up/down to navigate the history.

@effelle
Copy link
Contributor

effelle commented Mar 28, 2020

seems it remembers just the last command entered and if I press again the arrows Chrome comes in with his history cache.

@scottchiefbaker
Copy link
Author

I've tested on Firefox and it correctly remembers the last 20 commands. Anyone else able to test?

@to-scho
Copy link

to-scho commented Mar 29, 2020

works fine on a Mac in Safari (tested history of 20) and Chrome (tested history of 3 and gave up)

@arendst
Copy link
Owner

arendst commented Mar 29, 2020

Will test too today.

@arendst arendst removed the Awaiting feedback from Project Owner Awaiting feedback / input from Project Owner label Mar 29, 2020
arendst added a commit that referenced this issue Mar 29, 2020
Add Console command history (#8015)
@arendst
Copy link
Owner

arendst commented Mar 29, 2020

Implemented.

It has to fight with the browsers command cache but once you get used to it it works fine at least in Chrome and New Edge

arendst added a commit that referenced this issue Mar 29, 2020
Add console command history (#7483, #8015)
@ascillato2 ascillato2 added the fixed Result - The work on the issue has ended label Mar 29, 2020
@scottchiefbaker
Copy link
Author

@arendst you can add autocomplete="off" to the <input> tag and it won't compete with the browser like you mention.

IATkachenko pushed a commit to IATkachenko/Tasmota that referenced this issue Mar 29, 2020
Add Console command history (arendst#8015)
IATkachenko pushed a commit to IATkachenko/Tasmota that referenced this issue Mar 29, 2020
@arendst
Copy link
Owner

arendst commented Mar 30, 2020

@scottchiefbaker you don't happen to have some small bulletproof code to differentiate between tablets/phones (autocomplete="on") and PC's (autocomplete="off") do you?

@scottchiefbaker
Copy link
Author

@arendst easiest thing to do would be to check the screen with via JS. If screen width is less than 700px it's a mobile device.

I would think we'd be safe just turning autocomplete off for all platforms. I wouldn't use autocomplete on mobile, but maybe that's just me.

@arendst
Copy link
Owner

arendst commented Mar 30, 2020

It might also work if I leave the default (autocomplete on) and as soon as the up arrow or down arrow is detected set the property to off (which, in my eyes can only happen on a keyboard)

Testing...

@scottchiefbaker
Copy link
Author

@arendst that seems like a decent solution, and relatively easy to implement.

arendst added a commit that referenced this issue Mar 30, 2020
Turn browser autocomplete off and use command history as soon as an arrow key is pressed allowing mobiles and tablets to keep using browser autocomplete. (#8015)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

7 participants