feat: Implement JavaScript-based clipboard copy for error log
This commit is contained in:
parent
ac58fbb15c
commit
c162248348
@ -1,4 +1,5 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
from streamlit import components
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
import warnings
|
||||||
@ -521,10 +522,27 @@ if st.session_state.error_log:
|
|||||||
error_text = "\n\n".join([f"File: {path}\nError: {error}" for path, error in st.session_state.error_log.items()])
|
error_text = "\n\n".join([f"File: {path}\nError: {error}" for path, error in st.session_state.error_log.items()])
|
||||||
st.text_area("Error Details", error_text, height=200)
|
st.text_area("Error Details", error_text, height=200)
|
||||||
|
|
||||||
# Add copy button
|
# Add copy button with JavaScript to copy to clipboard
|
||||||
if st.button("Copy Error Log"):
|
copy_button = st.button("Copy Error Log")
|
||||||
st.write("Error log copied to clipboard!")
|
if copy_button:
|
||||||
st.session_state.error_log_copied = error_text
|
# Create a JavaScript function to copy the text
|
||||||
|
js_code = f"""
|
||||||
|
<script>
|
||||||
|
// Create a temporary textarea element
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.value = `{error_text.replace('`', '\\`')}`; // Escape backticks
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
|
||||||
|
// Select and copy the text
|
||||||
|
textarea.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
st.components.v1.html(js_code, height=0)
|
||||||
|
st.success("✅ Error log copied to clipboard!")
|
||||||
|
|
||||||
# Add clear button
|
# Add clear button
|
||||||
if st.button("Clear Error Log"):
|
if st.button("Clear Error Log"):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user