@@ -223,6 +223,16 @@ python3, ruby, rust, scala, swift, mysql, mssql, oraclesql.")
223
223
" Face for hard problems."
224
224
:group 'leetcode )
225
225
226
+ (defface leetcode-accepted-face
227
+ '((t (:foreground " #228b22" )))
228
+ " Face for submission accepted."
229
+ :group 'leetcode )
230
+
231
+ (defface leetcode-error-face
232
+ '((t (:foreground " #dc143c" )))
233
+ " Face for submission compile error, runtime error and TLE."
234
+ :group 'leetcode )
235
+
226
236
; ;; Login
227
237
; ; URL
228
238
(defconst leetcode--domain " leetcode.com" )
@@ -321,20 +331,17 @@ Such as 'Two Sum' will be converted to 'two-sum'. 'Pow(x, n)' will be 'powx-n'"
321
331
(hard-tag " hard" ))
322
332
(cond
323
333
((eq 1 difficulty)
324
- (prog1 easy-tag
325
- (put-text-property
326
- 0 (length easy-tag)
327
- 'font-lock-face 'leetcode-easy-face easy-tag)))
334
+ (leetcode--add-font-lock easy-tag 'leetcode-easy-face ))
328
335
((eq 2 difficulty)
329
- (prog1 medium-tag
330
- (put-text-property
331
- 0 (length medium-tag)
332
- 'font-lock-face 'leetcode-medium-face medium-tag)))
336
+ (leetcode--add-font-lock medium-tag 'leetcode-medium-face ))
333
337
((eq 3 difficulty)
334
- (prog1 hard-tag
335
- (put-text-property
336
- 0 (length hard-tag)
337
- 'font-lock-face 'leetcode-hard-face hard-tag))))))
338
+ (leetcode--add-font-lock hard-tag 'leetcode-hard-face )))))
339
+
340
+ (defun leetcode--add-font-lock (str face )
341
+ (prog1 str
342
+ (put-text-property
343
+ 0 (length str)
344
+ 'font-lock-face face str)))
338
345
339
346
(defun leetcode--detail-buffer-name (problem-id )
340
347
" Detail buffer name."
@@ -588,10 +595,7 @@ Return a list of rows, each row is a vector:
588
595
(vector
589
596
; ; status
590
597
(if (equal (leetcode-problem-status p) " ac" )
591
- (prog1 leetcode--checkmark
592
- (put-text-property
593
- 0 (length leetcode--checkmark)
594
- 'font-lock-face 'leetcode-checkmark-face leetcode--checkmark))
598
+ (leetcode--add-font-lock leetcode--checkmark 'leetcode-checkmark-face )
595
599
" " )
596
600
; ; id
597
601
(number-to-string (leetcode-problem-id p))
@@ -600,10 +604,7 @@ Return a list of rows, each row is a vector:
600
604
(leetcode-problem-title p)
601
605
" "
602
606
(if (eq (leetcode-problem-paid-only p) t )
603
- (prog1 leetcode--paid
604
- (put-text-property
605
- 0 (length leetcode--paid)
606
- 'font-lock-face 'leetcode-paid-face leetcode--paid))
607
+ (leetcode--add-font-lock leetcode--paid 'leetcode-paid-face )
607
608
" " ))
608
609
; ; acceptance
609
610
(leetcode-problem-acceptance p)
@@ -848,11 +849,11 @@ LeetCode require slug-title as the request parameters."
848
849
((eq .status_code 14 )
849
850
(insert .status_msg))
850
851
((eq .status_code 15 )
851
- (insert .status_msg)
852
+ (insert (leetcode--add-font-lock .status_msg 'leetcode-error-face ) )
852
853
(insert " \n\n " )
853
854
(insert .full_runtime_error))
854
855
((eq .status_code 20 )
855
- (insert .status_msg)
856
+ (insert (leetcode--add-font-lock .status_msg 'leetcode-error-face ) )
856
857
(insert " \n\n " )
857
858
(insert .full_compile_error)))
858
859
(when (> (length .code_output) 0 )
@@ -944,28 +945,38 @@ STATUS_CODE has following possible value:
944
945
(let-alist submission-detail
945
946
(with-current-buffer (get-buffer-create (leetcode--result-buffer-name problem-id))
946
947
(erase-buffer )
947
- (insert ( format " Status: %s " .status_msg) )
948
+ (font-lock-mode +1 )
948
949
(cond
949
950
((eq .status_code 10 )
950
- (insert (format " (%s /%s )\n\n " .total_correct .total_testcases))
951
+ (insert (format " Status: %s \n\n "
952
+ (leetcode--add-font-lock
953
+ (format " %s (%s /%s )" .status_msg .total_correct .total_testcases)
954
+ 'leetcode-accepted-face )))
951
955
(insert (format " Runtime: %s , faster than %. 2f%% of %s submissions.\n\n "
952
956
.status_runtime .runtime_percentile .pretty_lang))
953
957
(insert (format " Memory Usage: %s , less than %. 2f%% of %s submissions. "
954
958
.status_memory .memory_percentile .pretty_lang)))
955
959
((eq .status_code 11 )
956
- (insert (format " (%s /%s )\n\n " .total_correct .total_testcases))
960
+ (insert (format " Status: %s \n\n "
961
+ (leetcode--add-font-lock
962
+ (format " %s (%s /%s )" .status_msg .total_correct .total_testcases)
963
+ 'leetcode-error-face )))
957
964
(insert (format " Test Case: \n %s \n\n " .input))
958
965
(insert (format " Answer: %s \n\n " .code_output))
959
966
(insert (format " Expected Answer: %s \n\n " .expected_output))
960
- (insert (format " Stdout: \n %s \n " .std_output)))
967
+ (unless (string-empty-p .std_output)
968
+ (insert (format " Stdout: \n %s \n " .std_output))))
961
969
((eq .status_code 14 )
970
+ (insert (format " Status: %s " (leetcode--add-font-lock .status_msg 'leetcode-error-face )))
962
971
(insert " \n " ))
963
972
((eq .status_code 15 )
973
+ (insert (format " Status: %s " (leetcode--add-font-lock .status_msg 'leetcode-error-face )))
964
974
(insert " \n\n " )
965
- (insert (format ( alist-get ' full_runtime_error submission-detail) )))
975
+ (insert (format . full_runtime_error)))
966
976
((eq .status_code 20 )
977
+ (insert (format " Status: %s " (leetcode--add-font-lock .status_msg 'leetcode-error-face )))
967
978
(insert " \n\n " )
968
- (insert (format ( alist-get ' full_compile_error submission-detail) ))))
979
+ (insert (format . full_compile_error))))
969
980
(display-buffer (current-buffer )
970
981
'((display-buffer-reuse-window
971
982
leetcode--display-result)
0 commit comments