Add terminal code highlighting and editor opening functionality
Description
This PR enhances the open_asset command by adding syntax highlighting when displaying code snippets in the terminal and introducing the ability to open assets in the user's preferred editor.
Changes
Added terminal code highlighting using Pygments library.
Implemented a new -e flag for the open_asset command to open assets in an external editor.
Created a new config command to set and manage user preferences, including the preferred editor.
Modified the open_asset method to support these new features.
Implementation Details
Terminal Code Highlighting
Utilized Pygments library for syntax highlighting.
Added logic to determine the appropriate lexer based on the asset's language.
Implemented fallback to guess lexer if the language is not explicitly defined.
Editor Opening Functionality
Added a new config command to set and retrieve the user's preferred editor.
Implemented logic to open the asset in the configured editor when the -e flag is used.
Created a temporary file for editing and update the asset content after editing.
Testing
Tested the syntax highlighting functionality with various code snippets and languages.
Verified the editor opening functionality with VS Code.
Ensured the config command correctly saves and retrieves the editor preference.
you can use the following code for testing the terminal code highlighting :
ListCommand.list_command(type="assets")
meanwhile , for the code editor , change the code editor config via :
AssetsCommands.config(editor = "code")
and call the code editor to open using :
AssetsCommands.open_asset(item_index=1, open_in_editor=True)
you can use the -e flag in the terminal while calling it via the terminal as well .
Add terminal code highlighting and editor opening functionality
Description
This PR enhances the
open_asset
command by adding syntax highlighting when displaying code snippets in the terminal and introducing the ability to open assets in the user's preferred editor.Changes
-e
flag for theopen_asset
command to open assets in an external editor.config
command to set and manage user preferences, including the preferred editor.open_asset
method to support these new features.Implementation Details
Terminal Code Highlighting
Editor Opening Functionality
config
command to set and retrieve the user's preferred editor.-e
flag is used.Testing
you can use the following code for testing the terminal code highlighting :
ListCommand.list_command(type="assets")
meanwhile , for the code editor , change the code editor config via :
AssetsCommands.config(editor = "code")
and call the code editor to open using :
AssetsCommands.open_asset(item_index=1, open_in_editor=True)
you can use the -e flag in the terminal while calling it via the terminal as well .