Skip to content

Commit e424662

Browse files
committed
FancyBytes, Add printf output option
1 parent 8574218 commit e424662

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

components/FancyBytes.vue

+11-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<v-radio label="Ints (1 7 255)" value="ints"></v-radio>
1414
<v-radio label="Hex (01 07 FF)" value="hex"></v-radio>
1515
<v-radio label="Hex with 0x (0x01 0x07 0xFF)" value="hex0x"></v-radio>
16+
<v-radio label="Printf ('\\x01' '\\x07' '\\xFF')" value="printf" title="printf, ignores space and comma selections"></v-radio>
1617
</v-radio-group>
1718
<v-checkbox
1819
v-model="byteUpperCase"
@@ -164,7 +165,7 @@ export default defineComponent({
164165
// const byteCopyCommas = ref(localStorage.getItem('byteCopyCommas') === 'true');
165166
// const sendAddress = ref(localStorage.getItem('sendAddress') || '');
166167
// const byteUpperCase = ref(localStorage.getItem('byteUpperCase') === 'true');
167-
const byteDisplayType = ref<'ints' | 'hex' | 'hex0x'>('ints');
168+
const byteDisplayType = ref<'ints' | 'hex' | 'hex0x' | 'printf'>('ints');
168169
const byteCopySpaces = ref(true);
169170
const byteCopyCommas = ref(false);
170171
const sendAddress = ref('');
@@ -238,11 +239,15 @@ export default defineComponent({
238239
239240
const copyToClipboard = () => {
240241
let text = props.byteString.split(' ').map(byte => formatByte(byte)).join(' ');
241-
if (byteCopyCommas.value) {
242-
text = text.replace(/ /g, ', ');
243-
}
244-
if (!byteCopySpaces.value) {
245-
text = text.replace(/ /g, '');
242+
if (byteDisplayType.value === 'printf') {
243+
text = props.byteString.split(' ').map(byte => `'\\x${parseInt(byte).toString(16).padStart(2, '0')}'`).join('');
244+
} else {
245+
if (byteCopyCommas.value) {
246+
text = text.replace(/ /g, ', ');
247+
}
248+
if (!byteCopySpaces.value) {
249+
text = text.replace(/ /g, '');
250+
}
246251
}
247252
navigator.clipboard.writeText(text).then(() => {
248253
console.log('Copied to clipboard:', text);

0 commit comments

Comments
 (0)