feat: Change cli page
- New styles and strcture - Add event listeners - Add function to resize prompt according to input - Append prompts to history element
This commit is contained in:
parent
e76f457851
commit
c0c87771b6
2 changed files with 76 additions and 3 deletions
|
|
@ -4,7 +4,6 @@ tags:
|
|||
- ui
|
||||
---
|
||||
{% set pageId = page.fileSlug %}
|
||||
{% set pageClass = "h_full_view" %}
|
||||
{% set bodyClass = "body_frame" %}
|
||||
|
||||
{% extends "hippie/_app.njk" %}
|
||||
|
|
@ -25,10 +24,52 @@ tags:
|
|||
|
||||
{% block body %}
|
||||
{{ io.frameHeader('title-bar') }}
|
||||
<p>Previous return</p>
|
||||
<textarea name="prompt" id="prompt"></textarea>
|
||||
<div id="cli">
|
||||
<div id="history">
|
||||
<pre>Previous prompt</pre>
|
||||
</div>
|
||||
<div id="line">
|
||||
<textarea name="prefix" id="prefix" rows="1" cols="1" readonly>></textarea>
|
||||
<textarea name="prompt" id="prompt" rows="1" autofocus></textarea>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{%- block script %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
function resizeTextArea(textarea) {
|
||||
const {style, value} = textarea;
|
||||
|
||||
style.height = style.minHeight = 'auto';
|
||||
style.minHeight = `${Math.min(textarea.scrollHeight + 4, parseInt(textarea.style.maxHeight))}px`;
|
||||
style.height = `${textarea.scrollHeight}px`;
|
||||
}
|
||||
|
||||
const textarea = document.getElementById('prompt');
|
||||
|
||||
document.body.addEventListener('click', () => {
|
||||
textarea.focus();
|
||||
});
|
||||
|
||||
textarea.addEventListener('input', () => {
|
||||
resizeTextArea(textarea);
|
||||
});
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
|
||||
const p = document.createElement("pre");
|
||||
|
||||
p.textContent = event.target.value;
|
||||
document
|
||||
.getElementById("history")
|
||||
.appendChild(p);
|
||||
// window.scrollTo(0, document.body.scrollHeight);
|
||||
|
||||
event.target.value = '';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -4,6 +4,38 @@
|
|||
}
|
||||
}
|
||||
|
||||
#cli {
|
||||
@extend %flex-column;
|
||||
|
||||
background-color: black;
|
||||
|
||||
#line {
|
||||
@extend %flex-row;
|
||||
}
|
||||
|
||||
#prompt {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: .5em 0;
|
||||
color: white;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
max-height: 128px;
|
||||
margin: $margin_io;
|
||||
border: 0;
|
||||
padding: $space_half;
|
||||
// color: $color_text_io;
|
||||
color: white;
|
||||
// background-color: $color_back_io;
|
||||
background-color: transparent;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
.body_frame {
|
||||
@extend %flex-column;
|
||||
@extend .body_ui;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue